library(raster)

library(plyr)
library(dplyr)

library(ggplot2)
library(viridisLite)
library(colorspace)
library(RColorBrewer)

library(sf)
library(stringr)

library(ggpubr)
library(kableExtra)

memory.limit(size = 160000)
## [1] Inf

#display.brewer.pal(n = 11, name ="RdYlGn")
colorvec <- brewer.pal(n = 11, name ="RdYlGn")

1 Data

land_mask <- raster("Masks/land_sea_mask_1degree.nc4") 
land_mask.df <- as.data.frame(land_mask, xy = T) %>% setNames(c("lon","lat","lm")) # 0 if ocean, 1 if land


elev <- raster("Worldclim/wc2.1_10m/wc2.1_10m_elev.tif") 
elev.df <- elev %>% projectRaster(to = land_mask) %>% as.data.frame(xy = T) %>% setNames(c("lon","lat", "z"))


ipcc_regions <- shapefile("Masks/IPCC-WGI-reference-regions-v4.shp") %>% spTransform(crs("EPSG:4326")) 
ipcc_regions.raster <- ipcc_regions %>% rasterize(land_mask)
ipcc_regions.df <- as.data.frame(ipcc_regions.raster, xy = T) %>% setNames(c("lon","lat","Continent","Type","Name","Acronym"))
tas.all_annual <- read.table("CMIP6/tas/tas.all_annual.txt")
pr.all_annual <- read.table("CMIP6/pr/pr.all_annual.txt")
sfcWind.all_annual <- read.table("CMIP6/sfcWind/sfcWind.all_annual.txt")
hfls.all_annual <- read.table("CMIP6/hfls/hfls.all_annual.txt")
hfss.all_annual <- read.table("CMIP6/hfss/hfss.all_annual.txt")
hurs.all_annual <- read.table("CMIP6/hurs/hurs.all_annual.txt")

cmip6_annual <- tas.all_annual %>% merge(pr.all_annual, by = c("lon","lat","model","period","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(sfcWind.all_annual, by = c("lon","lat","model","period","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hfls.all_annual, by = c("lon","lat","model","period","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hfss.all_annual, by = c("lon","lat","model","period","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hurs.all_annual, by = c("lon","lat","model","period","lm", "Continent","Type","Name","Acronym","source")) %>% 
  merge(elev.df, by = c("lon", "lat"))

write.table(cmip6_annual, "cmip6_annual.txt")
tas.all_january <- read.table("CMIP6/tas/tas.all_january.txt")
pr.all_january <- read.table("CMIP6/pr/pr.all_january.txt")
sfcWind.all_january <- read.table("CMIP6/sfcWind/sfcWind.all_january.txt")
hfls.all_january <- read.table("CMIP6/hfls/hfls.all_january.txt")
hfss.all_january <- read.table("CMIP6/hfss/hfss.all_january.txt")
hurs.all_january <- read.table("CMIP6/hurs/hurs.all_january.txt")

cmip6_january <- tas.all_january %>% merge(pr.all_january, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(sfcWind.all_january, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hfls.all_january, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hfss.all_january, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hurs.all_january, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>% 
  merge(elev.df, by = c("lon", "lat"))

write.table(cmip6_january, "cmip6_january.txt")
tas.all_february <- read.table("CMIP6/tas/tas.all_february.txt")
pr.all_february <- read.table("CMIP6/pr/pr.all_february.txt")
sfcWind.all_february <- read.table("CMIP6/sfcWind/sfcWind.all_february.txt")
hfls.all_february <- read.table("CMIP6/hfls/hfls.all_february.txt")
hfss.all_february <- read.table("CMIP6/hfss/hfss.all_february.txt")
hurs.all_february <- read.table("CMIP6/hurs/hurs.all_february.txt")

cmip6_february <- tas.all_february %>% merge(pr.all_february, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(sfcWind.all_february, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hfls.all_february, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hfss.all_february, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hurs.all_february, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>% 
  merge(elev.df, by = c("lon", "lat"))

write.table(cmip6_february, "cmip6_february.txt")
tas.all_march <- read.table("CMIP6/tas/tas.all_march.txt")
pr.all_march <- read.table("CMIP6/pr/pr.all_march.txt")
sfcWind.all_march <- read.table("CMIP6/sfcWind/sfcWind.all_march.txt")
hfls.all_march <- read.table("CMIP6/hfls/hfls.all_march.txt")
hfss.all_march <- read.table("CMIP6/hfss/hfss.all_march.txt")
hurs.all_march <- read.table("CMIP6/hurs/hurs.all_march.txt")

cmip6_march <- tas.all_march %>% merge(pr.all_march, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(sfcWind.all_march, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hfls.all_march, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hfss.all_march, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hurs.all_march, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>% 
  merge(elev.df, by = c("lon", "lat"))

write.table(cmip6_march, "cmip6_march.txt")
tas.all_april <- read.table("CMIP6/tas/tas.all_april.txt")
pr.all_april <- read.table("CMIP6/pr/pr.all_april.txt")
sfcWind.all_april <- read.table("CMIP6/sfcWind/sfcWind.all_april.txt")
hfls.all_april <- read.table("CMIP6/hfls/hfls.all_april.txt")
hfss.all_april <- read.table("CMIP6/hfss/hfss.all_april.txt")
hurs.all_april <- read.table("CMIP6/hurs/hurs.all_april.txt")

cmip6_april <- tas.all_april %>% merge(pr.all_april, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(sfcWind.all_april, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hfls.all_april, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hfss.all_april, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hurs.all_april, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>% 
  merge(elev.df, by = c("lon", "lat"))

write.table(cmip6_april, "cmip6_april.txt")
tas.all_may <- read.table("CMIP6/tas/tas.all_may.txt")
pr.all_may <- read.table("CMIP6/pr/pr.all_may.txt")
sfcWind.all_may <- read.table("CMIP6/sfcWind/sfcWind.all_may.txt")
hfls.all_may <- read.table("CMIP6/hfls/hfls.all_may.txt")
hfss.all_may <- read.table("CMIP6/hfss/hfss.all_may.txt")
hurs.all_may <- read.table("CMIP6/hurs/hurs.all_may.txt")

cmip6_may <- tas.all_may %>% merge(pr.all_may, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(sfcWind.all_may, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hfls.all_may, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hfss.all_may, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hurs.all_may, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>% 
  merge(elev.df, by = c("lon", "lat"))

write.table(cmip6_may, "cmip6_may.txt")
tas.all_june <- read.table("CMIP6/tas/tas.all_june.txt")
pr.all_june <- read.table("CMIP6/pr/pr.all_june.txt")
sfcWind.all_june <- read.table("CMIP6/sfcWind/sfcWind.all_june.txt")
hfls.all_june <- read.table("CMIP6/hfls/hfls.all_june.txt")
hfss.all_june <- read.table("CMIP6/hfss/hfss.all_june.txt")
hurs.all_june <- read.table("CMIP6/hurs/hurs.all_june.txt")

cmip6_june <- tas.all_june %>% merge(pr.all_june, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(sfcWind.all_june, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hfls.all_june, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hfss.all_june, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hurs.all_june, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>% 
  merge(elev.df, by = c("lon", "lat"))

write.table(cmip6_june, "cmip6_june.txt")
tas.all_july <- read.table("CMIP6/tas/tas.all_july.txt")
pr.all_july <- read.table("CMIP6/pr/pr.all_july.txt")
sfcWind.all_july <- read.table("CMIP6/sfcWind/sfcWind.all_july.txt")
hfls.all_july <- read.table("CMIP6/hfls/hfls.all_july.txt")
hfss.all_july <- read.table("CMIP6/hfss/hfss.all_july.txt")
hurs.all_july <- read.table("CMIP6/hurs/hurs.all_july.txt")

cmip6_july <- tas.all_july %>% merge(pr.all_july, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(sfcWind.all_july, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hfls.all_july, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hfss.all_july, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hurs.all_july, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>% 
  merge(elev.df, by = c("lon", "lat"))
 
write.table(cmip6_july, "cmip6_july.txt")
tas.all_august <- read.table("CMIP6/tas/tas.all_august.txt")
pr.all_august <- read.table("CMIP6/pr/pr.all_august.txt")
sfcWind.all_august <- read.table("CMIP6/sfcWind/sfcWind.all_august.txt")
hfls.all_august <- read.table("CMIP6/hfls/hfls.all_august.txt")
hfss.all_august <- read.table("CMIP6/hfss/hfss.all_august.txt")
hurs.all_august <- read.table("CMIP6/hurs/hurs.all_august.txt")

cmip6_august <- tas.all_august %>% merge(pr.all_august, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(sfcWind.all_august, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hfls.all_august, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hfss.all_august, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hurs.all_august, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>% 
  merge(elev.df, by = c("lon", "lat"))

write.table(cmip6_august, "cmip6_august.txt")
tas.all_september <- read.table("CMIP6/tas/tas.all_september.txt")
pr.all_september <- read.table("CMIP6/pr/pr.all_september.txt")
sfcWind.all_september <- read.table("CMIP6/sfcWind/sfcWind.all_september.txt")
hfls.all_september <- read.table("CMIP6/hfls/hfls.all_september.txt")
hfss.all_september <- read.table("CMIP6/hfss/hfss.all_september.txt")
hurs.all_september <- read.table("CMIP6/hurs/hurs.all_september.txt")

cmip6_september <- tas.all_september %>% merge(pr.all_september, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(sfcWind.all_september, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hfls.all_september, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hfss.all_september, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hurs.all_september, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>% 
  merge(elev.df, by = c("lon", "lat"))

write.table(cmip6_september, "cmip6_september.txt")
tas.all_october <- read.table("CMIP6/tas/tas.all_october.txt")
pr.all_october <- read.table("CMIP6/pr/pr.all_october.txt")
sfcWind.all_october <- read.table("CMIP6/sfcWind/sfcWind.all_october.txt")
hfls.all_october <- read.table("CMIP6/hfls/hfls.all_october.txt")
hfss.all_october <- read.table("CMIP6/hfss/hfss.all_october.txt")
hurs.all_october <- read.table("CMIP6/hurs/hurs.all_october.txt")

cmip6_october <- tas.all_october %>% merge(pr.all_october, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(sfcWind.all_october, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hfls.all_october, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hfss.all_october, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hurs.all_october, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>% 
  merge(elev.df, by = c("lon", "lat"))

write.table(cmip6_october, "cmip6_october.txt")
tas.all_november <- read.table("CMIP6/tas/tas.all_november.txt")
pr.all_november <- read.table("CMIP6/pr/pr.all_november.txt")
sfcWind.all_november <- read.table("CMIP6/sfcWind/sfcWind.all_november.txt")
hfls.all_november <- read.table("CMIP6/hfls/hfls.all_november.txt")
hfss.all_november <- read.table("CMIP6/hfss/hfss.all_november.txt")
hurs.all_november <- read.table("CMIP6/hurs/hurs.all_november.txt")

cmip6_november <- tas.all_november %>% merge(pr.all_november, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(sfcWind.all_november, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hfls.all_november, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hfss.all_november, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hurs.all_november, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>% 
  merge(elev.df, by = c("lon", "lat"))

write.table(cmip6_november, "cmip6_november.txt")
tas.all_december <- read.table("CMIP6/tas/tas.all_december.txt")
pr.all_december <- read.table("CMIP6/pr/pr.all_december.txt")
sfcWind.all_december <- read.table("CMIP6/sfcWind/sfcWind.all_december.txt")
hfls.all_december <- read.table("CMIP6/hfls/hfls.all_december.txt")
hfss.all_december <- read.table("CMIP6/hfss/hfss.all_december.txt")
hurs.all_december <- read.table("CMIP6/hurs/hurs.all_december.txt")

cmip6_december <- tas.all_december %>% merge(pr.all_december, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(sfcWind.all_december, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hfls.all_december, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hfss.all_december, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>%
  merge(hurs.all_december, by = c("lon","lat","model","period","month","lm", "Continent","Type","Name","Acronym","source")) %>% 
  merge(elev.df, by = c("lon", "lat"))

write.table(cmip6_december, "cmip6_december.txt")

2 Aridity Index

2.1 De Martonne

cmip6 <- read.table("cmip6_annual.txt")

breaks.martonne <- c(0,5,10,20,"30","40",Inf)
cat.martonne <- c("[0,5]" = "Desert", "(5,10]"= "Arid", "(10,20]" = "Semi-arid","(20,30]" = "Temperate", "(30,40]" = "Humid", "(40,Inf]" = "Forest")
col.martonne <- c("Desert" = colorvec[2], "Arid"= colorvec[4],"Semi-arid"= colorvec[5], "Temperate" = colorvec[8], "Humid"= colorvec[10],"Forest"= colorvec[11])

cmip6$AIm <- with(cmip6,pr*60*60*24*365/(tas-273.15+10)) # pr in mm/y, tas in Ceslsius


cmip6$cat.AIm <- cmip6$AIm %>% cut(breaks.martonne, include.lowest = T) %>% revalue(cat.martonne)


map_list <- list()

for(i in unique(cmip6$source)){
g <- ggplot(data = subset(cmip6, period == "1970_2000" & source == i)) + geom_raster(aes(x=lon, y = lat,  fill = cat.AIm))+
  scale_fill_manual(values = col.martonne, na.translate = F)+
  labs(title = paste(i, "1970-2000", sep = ", "), fill = "")+
  theme_void()
map_list[[i]] <- g
}

ggpubr::ggarrange(plotlist = map_list, ncol = 3, nrow = 5, common.legend = T, legend = "bottom")

2.2 UNEP

ea from Rh:

ea = 6.108(RH/100)exp(17.27*T/(T+237.3)) Refs https://www.nature.com/articles/s41598-023-40499-6 : Allen and Tetens

id_vars <- c("lon","lat","model","period","lm", "Continent","Type","Name","Acronym","source")

cmip6_annual <- mutate(read.table("cmip6_annual.txt"),
                  t = tas - 273.15,
                  Rn = (hfls + hfss) * 86400 * 1e-6, # conversion from W/m2 to MJ/m2/day.
                  P = 101.3 * ((293-0.0065*z)/293)^(5.26),
                  es = 0.61078*exp(17.27*t/(t+237.3)),
                  ea = (hurs/100)*es,
                  delta = 4098*es/(t+237.3)^2, #slope vapor pressure
                  gamma = 0.00163*P/(2.501-52.6361e-3*t), #psychrometric constant
                  ET0_annual = ((0.408*delta*Rn+gamma*900/((t)+273)*0.748*sfcWind*(es-ea))/(delta+gamma*(1+0.34*0.748*sfcWind)))) 

cmip6_01 <- mutate(read.table("cmip6_january.txt"),
                   t = tas - 273.15,
                   pr_01 = pr*60*60*24, # mm/day
                   Rn = (hfls + hfss) * 86400 * 1e-6, # conversion from W/m2 to MJ/m2/day.
                   P = 101.3 * ((293-0.0065*z)/293)^(5.26),
                   es = 0.61078*exp(17.27*t/(t+237.3)),
                   ea = (hurs/100)*es,
                  delta = 4098*es/(t+237.3)^2, #slope vapor pressure
                  gamma = 0.00163*P/(2.501-52.6361e-3*t), #psychrometric constant
                  ET0_01 = ((0.408*delta*Rn+gamma*900/(t+273)*0.748*sfcWind*(es-ea))/(delta+gamma*(1+0.34*0.748*sfcWind)))) # Evapotranspiration, G considered to be negligible. in mm/day. Wind speed at 10 m is converted to wind speed at 2 m by multiplying by 0.748

cmip6_02 <- mutate(read.table("cmip6_february.txt"),
                   t = tas - 273.15,
                   pr_02 = pr*60*60*24, # mm/day
                   Rn = (hfls + hfss) * 86400 * 1e-6, # conversion from W/m2 to MJ/m2/day.
                   P = 101.3 * ((293-0.0065*z)/293)^(5.26),
                   es = 0.61078*exp(17.27*t/(t+237.3)),
                   ea = (hurs/100)*es,
                  delta = 4098*es/(t+237.3)^2, #slope vapor pressure
                  gamma = 0.00163*P/(2.501-52.6361e-3*t), #psychrometric constant
                  ET0_02 = ((0.408*delta*Rn+gamma*900/(t+273)*0.748*sfcWind*(es-ea))/(delta+gamma*(1+0.34*0.748*sfcWind))))

cmip6_03 <- mutate(read.table("cmip6_march.txt"),
                   t = tas - 273.15,
                   pr_03 = pr*60*60*24, # mm/day
                   Rn = (hfls + hfss) * 86400 * 1e-6, # conversion from W/m2 to MJ/m2/day.
                   P = 101.3 * ((293-0.0065*z)/293)^(5.26),
                   es = 0.61078*exp(17.27*t/(t+237.3)),
                   ea = (hurs/100)*es,
                  delta = 4098*es/(t+237.3)^2, #slope vapor pressure
                  gamma = 0.00163*P/(2.501-52.6361e-3*t), #psychrometric constant
                  ET0_03 = ((0.408*delta*Rn+gamma*900/(t+273)*0.748*sfcWind*(es-ea))/(delta+gamma*(1+0.34*0.748*sfcWind))))

cmip6_04 <- mutate(read.table("cmip6_april.txt"),
                   t = tas - 273.15,
                   pr_04 = pr*60*60*24, # mm/day
                   Rn = (hfls + hfss) * 86400 * 1e-6, # conversion from W/m2 to MJ/m2/day.
                   P = 101.3 * ((293-0.0065*z)/293)^(5.26),
                  es = 0.61078*exp(17.27*t/(t+237.3)),
                  ea = (hurs/100)*es,
                  delta = 4098*es/(t+237.3)^2, #slope vapor pressure
                  gamma = 0.00163*P/(2.501-52.6361e-3*t), #psychrometric constant
                  ET0_04 = ((0.408*delta*Rn+gamma*900/(t+273)*0.748*sfcWind*(es-ea))/(delta+gamma*(1+0.34*0.748*sfcWind))))

cmip6_05 <- mutate(read.table("cmip6_may.txt"),
                   t = tas - 273.15,
                   pr_05 = pr*60*60*24, # mm/day
                   Rn = (hfls + hfss) * 86400 * 1e-6, # conversion from W/m2 to MJ/m2/day.
                   P = 101.3 * ((293-0.0065*z)/293)^(5.26),
                   es = 0.61078*exp(17.27*t/(t+237.3)),
                   ea = (hurs/100)*es,
                  delta = 4098*es/(t+237.3)^2, #slope vapor pressure
                  gamma = 0.00163*P/(2.501-52.6361e-3*t), #psychrometric constant
                  ET0_05 = ((0.408*delta*Rn+gamma*900/(t+273)*0.748*sfcWind*(es-ea))/(delta+gamma*(1+0.34*0.748*sfcWind))))

cmip6_06 <- mutate(read.table("cmip6_june.txt"),
                   t = tas - 273.15,
                   pr_06 = pr*60*60*24, # mm/day
                   Rn = (hfls + hfss) * 86400 * 1e-6, # conversion from W/m2 to MJ/m2/day.
                   P = 101.3 * ((293-0.0065*z)/293)^(5.26),
                   es = 0.61078*exp(17.27*t/(t+237.3)),
                   ea = (hurs/100)*es,
                  delta = 4098*es/(t+237.3)^2, #slope vapor pressure
                  gamma = 0.00163*P/(2.501-52.6361e-3*t), #psychrometric constant
                  ET0_06 = ((0.408*delta*Rn+gamma*900/(t+273)*0.748*sfcWind*(es-ea))/(delta+gamma*(1+0.34*0.748*sfcWind))))

cmip6_07 <- mutate(read.table("cmip6_july.txt"),
                   t = tas - 273.15,
                   pr_07 = pr*60*60*24, # mm/day
                   Rn = (hfls + hfss) * 86400 * 1e-6, # conversion from W/m2 to MJ/m2/day.
                   P = 101.3 * ((293-0.0065*z)/293)^(5.26),
                   es = 0.61078*exp(17.27*t/(t+237.3)),
                   ea = (hurs/100)*es,
                  delta = 4098*es/(t+237.3)^2, #slope vapor pressure
                  gamma = 0.00163*P/(2.501-52.6361e-3*t), #psychrometric constant
                  ET0_07 = ((0.408*delta*Rn+gamma*900/(t+273)*0.748*sfcWind*(es-ea))/(delta+gamma*(1+0.34*0.748*sfcWind))))

cmip6_08 <- mutate(read.table("cmip6_august.txt"),
                   t = tas - 273.15,
                   pr_08 = pr*60*60*24, # mm/day
                   Rn = (hfls + hfss) * 86400 * 1e-6, # conversion from W/m2 to MJ/m2/day.
                   P = 101.3 * ((293-0.0065*z)/293)^(5.26),
                   es = 0.61078*exp(17.27*t/(t+237.3)),
                   ea = (hurs/100)*es,
                  delta = 4098*es/(t+237.3)^2, #slope vapor pressure
                  gamma = 0.00163*P/(2.501-52.6361e-3*t), #psychrometric constant
                  ET0_08 = ((0.408*delta*Rn+gamma*900/(t+273)*0.748*sfcWind*(es-ea))/(delta+gamma*(1+0.34*0.748*sfcWind))))

cmip6_09 <- mutate(read.table("cmip6_september.txt"),
                   t = tas - 273.15,
                   pr_09 = pr*60*60*24, # mm/day
                   Rn = (hfls + hfss) * 86400 * 1e-6, # conversion from W/m2 to MJ/m2/day.
                   P = 101.3 * ((293-0.0065*z)/293)^(5.26),
                   es = 0.61078*exp(17.27*t/(t+237.3)),
                   ea = (hurs/100)*es,
                  delta = 4098*es/(t+237.3)^2, #slope vapor pressure
                  gamma = 0.00163*P/(2.501-52.6361e-3*t), #psychrometric constant
                  ET0_09 = ((0.408*delta*Rn+gamma*900/(t+273)*0.748*sfcWind*(es-ea))/(delta+gamma*(1+0.34*0.748*sfcWind))))

cmip6_10 <- mutate(read.table("cmip6_october.txt"),
                   t = tas - 273.15,
                   pr_10 = pr*60*60*24, # mm/day
                   Rn = (hfls + hfss) * 86400 * 1e-6, # conversion from W/m2 to MJ/m2/day.
                   P = 101.3 * ((293-0.0065*z)/293)^(5.26),
                   es = 0.61078*exp(17.27*t/(t+237.3)),
                   ea = (hurs/100)*es,
                  delta = 4098*es/(t+237.3)^2, #slope vapor pressure
                  gamma = 0.00163*P/(2.501-52.6361e-3*t), #psychrometric constant
                  ET0_10 = ((0.408*delta*Rn+gamma*900/(t+273)*0.748*sfcWind*(es-ea))/(delta+gamma*(1+0.34*0.748*sfcWind))))

cmip6_11 <- mutate(read.table("cmip6_november.txt"),
                   t = tas - 273.15,
                   pr_11 = pr*60*60*24, # mm/day
                   Rn = (hfls + hfss) * 86400 * 1e-6, # conversion from W/m2 to MJ/m2/day.
                   P = 101.3 * ((293-0.0065*z)/293)^(5.26),
                   es = 0.61078*exp(17.27*t/(t+237.3)),
                   ea = (hurs/100)*es,
                  delta = 4098*es/(t+237.3)^2, #slope vapor pressure
                  gamma = 0.00163*P/(2.501-52.6361e-3*t), #psychrometric constant
                  ET0_11 = ((0.408*delta*Rn+gamma*900/(t+273)*0.748*sfcWind*(es-ea))/(delta+gamma*(1+0.34*0.748*sfcWind))))

cmip6_12 <- mutate(read.table("cmip6_december.txt"),
                   t = tas - 273.15,
                   pr_12 = pr*60*60*24, # mm/day
                   Rn = (hfls + hfss) * 86400 * 1e-6, # conversion from W/m2 to MJ/m2/day.
                   P = 101.3 * ((293-0.0065*z)/293)^(5.26),
                   es = 0.61078*exp(17.27*t/(t+237.3)),
                   ea = (hurs/100)*es,
                  delta = 4098*es/(t+237.3)^2, #slope vapor pressure
                  gamma = 0.00163*P/(2.501-52.6361e-3*t), #psychrometric constant
                  ET0_12 = ((0.408*delta*Rn+gamma*900/(t+273)*0.748*sfcWind*(es-ea))/(delta+gamma*(1+0.34*0.748*sfcWind))))

et0_monthly <- select(cmip6_annual, id_vars) %>%
  merge(select(cmip6_01, c(id_vars, "ET0_01", "pr_01")), by = id_vars) %>%
  merge(select(cmip6_02, c(id_vars, "ET0_02", "pr_02")), by = id_vars) %>%
  merge(select(cmip6_03, c(id_vars, "ET0_03", "pr_03")), by = id_vars) %>%
  merge(select(cmip6_04, c(id_vars, "ET0_04", "pr_04")), by = id_vars) %>%
  merge(select(cmip6_05, c(id_vars, "ET0_05", "pr_05")), by = id_vars) %>%
  merge(select(cmip6_06, c(id_vars, "ET0_06", "pr_06")), by = id_vars) %>%
  merge(select(cmip6_07, c(id_vars, "ET0_07", "pr_07")), by = id_vars) %>%
  merge(select(cmip6_08, c(id_vars, "ET0_08", "pr_08")), by = id_vars) %>%
  merge(select(cmip6_09, c(id_vars, "ET0_09", "pr_09")), by = id_vars) %>%
  merge(select(cmip6_10, c(id_vars, "ET0_10", "pr_10")), by = id_vars) %>%   
  merge(select(cmip6_11, c(id_vars, "ET0_11", "pr_11")), by = id_vars) %>%
  merge(select(cmip6_12, c(id_vars, "ET0_12", "pr_12")), by = id_vars)

et0_monthly$spr <- with(et0_monthly, pr_01*31 + pr_02 * 28 + pr_03 * 31 + pr_04 * 30 + pr_05 * 31 + pr_06 * 30 +
                           pr_07 * 31 + pr_08 * 31 + pr_09 * 30 + pr_10 * 31 + pr_11 * 30 + pr_12 * 31)
et0_monthly$sET0 <- with(et0_monthly, ET0_01*31 + ET0_02 * 28 + ET0_03 * 31 + ET0_04 * 30 + ET0_05 * 31 + ET0_06 * 30 +
                           ET0_07 * 31 + ET0_08 * 31 + ET0_09 * 30 + ET0_10 * 31 + ET0_11 * 30 + ET0_12 * 31)

cmip6 <- merge(cmip6_annual, et0_monthly, by = id_vars)
cmip6$AI <- with(cmip6, abs(spr/sET0))  
cmip6$AI_annual <- with(cmip6, abs((pr*60*60*24*365)/(ET0_annual*365)))

breaks.unesco <- c(-Inf,0,0.03,0.2,0.5,0.65,Inf)
cat.unesco <- c("(0,0.03]"= "Hyperarid", "(0.03,0.2]" = "Arid", "(0.2,0.5]" = "Semi-arid", "(0.5,0.65]" = "Dry subhumid","(0.65, Inf]" = "Humid", "(-Inf,0]" = "Cold")
col.cat <- c("Hyperarid" = colorvec[2], "Arid"= colorvec[4],"Semi-arid"= colorvec[5], "Dry subhumid" = colorvec[8], "Humid"= colorvec[10], "Cold" = "powderblue")

cmip6$cat.AI <- cmip6$AI %>% cut(breaks = breaks.unesco) %>% revalue(cat.unesco)
cmip6$cat.AI[which(cmip6$sET0 < 400)] <- "Cold"
cmip6$cat.AI %>% unique()

cmip6$cat.AI <- cmip6$AI %>% cut(breaks = breaks.unesco) %>% 
  revalue(cat.unesco)


cmip6$cat.AI_annual <- cmip6$AI_annual %>% cut(breaks = breaks.unesco) %>% 
  revalue(cat.unesco)

cmip6$cat.AI_annual[which(cmip6$ET0_annual*365 < 400)] <- "Cold"

write.table(cmip6, "cmip6_AI.txt")

cmip6 <- read.table("cmip6_AI.txt")

cmip6_AI <- cmip6 %>% subset(period == "1970_2000") %>%
   group_by(lon,lat,Continent, Type, Name, Acronym, lm, model, z) %>% 
   dplyr::summarise(tas = mean(tas, na.rm = T) - 273.15, pr = mean(pr, na.rm = T) * 60 * 60 * 24 * 365,
                   sfcWind = mean(sfcWind, na.rm = T), Rn = mean(Rn, na.rm = T),
                   ea = mean(ea, na.rm = T), ET0 = mean(sET0, na.rm = T), AI = mean(AI, na.rm = T)) %>%
  ungroup() %>%  
  mutate(source = "CMIP6")%>%
   select(c("lon","lat","Continent","Type","Name","Acronym","lm","model","source","pr","tas","sfcWind","Rn", "ea","z","ET0","AI"))


write.table(cmip6_AI, "cmip6ref.txt")

3 Maps AI by model

cmip6 <- read.table("cmip6_AI.txt")

breaks.unesco <- c(-Inf,0.03,0.2,0.5,0.65,Inf)
cat.unesco <- c("(-Inf,0.03]"= "Hyperarid", "(0.03,0.2]" = "Arid", "(0.2,0.5]" = "Semi-arid", "(0.5,0.65]" = "Dry subhumid","(0.65, Inf]" = "Humid")

col.cat <- c("Hyperarid" = colorvec[2], "Arid"= colorvec[4],"Semi-arid"= colorvec[5], "Dry subhumid" = colorvec[8], "Humid"= colorvec[10], "Cold" = "powderblue")

3.1 1850-1880

map_list <- list()

for(i in unique(cmip6$source)){
g <- ggplot(data = subset(cmip6, period == "1850_1880" & source == i)) + geom_raster(aes(x=lon, y = lat,  fill = cat.AI))+
  scale_fill_manual(values = col.cat, na.translate = F)+
  labs(title = paste(i, "1850-1880", sep = ", "), fill = "")+
  theme_void()
map_list[[i]] <- g
}

ggpubr::ggarrange(plotlist = map_list, ncol = 3, nrow = 5, common.legend = T, legend = "bottom")


sdmm <- cmip6 %>% subset(period == "1850_1880" & !Continent %in% c("SOUTHERN","PACIFIC","ATLANTIC","INDIAN","ARCTIC")) %>%
  group_by(source, cat.AI) %>%
  summarise(count = n()) %>%
  ungroup() %>% group_by(source) %>% mutate(percent = round(count/sum(count)*100, 1), count = NULL) %>%
  ungroup() %>% group_by(cat.AI) %>% summarise(mean = round(mean(percent, na.rm = T),1), sd = round(sd(percent, na.rm = T),1)) %>%
  t() %>% as.data.frame() %>% setNames(c(.[1,1:6], "NA")) %>% .[-1, ] %>% sapply(as.numeric) %>% as.data.frame() %>%
  mutate("Sum drylands" = rowSums(.[c("Hyperarid","Arid","Semi-arid","Dry subhumid")]), "source" = c("mean","sd")) %>%
  select(c("source","Hyperarid","Arid","Semi-arid","Dry subhumid","Sum drylands","Humid","Cold","NA"))


tab <- cmip6 %>% subset(period == "1850_1880" & !Continent %in% c("SOUTHERN","PACIFIC","ATLANTIC","INDIAN","ARCTIC")) %>%
  group_by(source, cat.AI) %>%
  summarise(count = n()) %>%
  ungroup() %>% group_by(source) %>% mutate(percent = round(count/sum(count)*100, 1), count = NULL) %>%
  reshape2::dcast(source~cat.AI) %>%
  mutate("Sum drylands" = rowSums(.[c("Hyperarid","Arid","Semi-arid","Dry subhumid")])) %>%
  select(c("source","Hyperarid","Arid","Semi-arid","Dry subhumid","Sum drylands","Humid","Cold","NA")) %>% 
  rbind(sdmm)


knitr::kable(tab, digits = 2, escape = F)  %>%
  kable_styling(bootstrap_options = "bordered") %>% 
  column_spec(c(6,9), italic = T, include_thead = T) %>% row_spec(c(14,15), bold = T) 
source Hyperarid Arid Semi-arid Dry subhumid Sum drylands Humid Cold NA
CAS-ESM2 3.6 6.3 9.2 4.3 23.4 26.4 47.7 2.6
CESM 3.6 7.5 10.2 3.5 24.8 24.8 47.8 2.6
CMCC 3.9 5.0 6.6 3.7 19.2 29.3 48.9 2.6
CMCC-ESM2 4.2 5.7 5.2 1.9 17.0 16.7 63.6 2.6
CNRM 4.0 8.4 8.0 4.6 25.0 26.4 46.0 2.6
EC-Earth3 6.0 6.2 7.6 3.1 22.9 25.6 48.9 2.6
FGOALS 3.9 8.9 11.0 5.0 28.8 20.8 47.8 2.6
GFDL-ESM4 3.9 6.5 6.1 2.9 19.4 25.8 52.3 2.6
INM 3.0 5.7 9.4 4.0 22.1 28.2 47.0 2.6
INM-CM5 2.4 6.2 8.0 3.9 20.5 30.0 46.9 2.6
MPI 5.9 7.6 7.0 3.0 23.5 24.0 49.9 2.6
MRI 4.4 7.4 6.0 2.7 20.5 27.5 49.5 2.6
NorESM-2-MM 3.6 7.3 12.8 4.1 27.8 24.7 45.0 2.6
mean 4.0 6.8 8.2 3.6 22.6 25.4 49.3 2.6
sd 1.0 1.1 2.2 0.9 5.2 3.5 4.7 0.0

3.2 1970-2000

map_list <- list()

for(i in unique(cmip6$source)){
g <- ggplot(data = subset(cmip6, period == "1970_2000" & source == i)) + geom_raster(aes(x=lon, y = lat,  fill = cat.AI))+
  scale_fill_manual(values = col.cat, na.translate = F)+
  labs(title = paste(i, "1850-1880", sep = ", "), fill = "")+
  theme_void()
map_list[[i]] <- g
}

ggpubr::ggarrange(plotlist = map_list, ncol = 3, nrow = 5, common.legend = T, legend = "bottom")

library(ggrepel) 

pie <- cmip6 %>% subset(period == "1970_2000" & !Continent %in% c("SOUTHERN","PACIFIC","POLAR","ATLANTIC","INDIAN","ARCTIC")) %>%
  select(c("source", "cat.AI")) %>%
  reshape2::melt(id.vars = c("source")) %>%
  group_by(source, value) %>%
  summarise(count = n()) %>%
  mutate(perc = round(count/sum(count)*100, 1),
         lab.y = rev(cumsum(rev(count))) - count*0.5) %>% 
  ungroup() 

pie_list <- list()

for(i in unique(pie$source)){
 p <- ggplot(subset(pie, source == i))+
    geom_bar(aes(x = "", y = count, fill = value), width = 1, stat = "identity")+
  coord_polar("y", start = 0)+
  scale_fill_manual(values = col.cat)+
  geom_label_repel(aes(x = "", y = lab.y, label = perc), nudge_x = 0.5)+
  labs(fill = "", title = i)+
  theme_void()+theme(legend.position = "right")
pie_list[[i]] <- p
}

ggpubr::ggarrange(plotlist = pie_list, nrow = 4, ncol = 4, common.legend = T, legend = "bottom")


sdmm <- cmip6 %>% subset(period == "1970_2000" & !Continent %in% c("SOUTHERN","PACIFIC","ATLANTIC","INDIAN","ARCTIC")) %>%
  group_by(source, cat.AI) %>%
  summarise(count = n()) %>%
  ungroup() %>% group_by(source) %>% mutate(percent = round(count/sum(count)*100, 1), count = NULL) %>%
  ungroup() %>% group_by(cat.AI) %>% summarise(mean = round(mean(percent, na.rm = T),1), sd = round(sd(percent, na.rm = T),1)) %>%
  t() %>% as.data.frame() %>% setNames(c(.[1,1:6], "NA")) %>% .[-1, ] %>% sapply(as.numeric) %>% as.data.frame() %>%
  mutate("Sum drylands" = rowSums(.[c("Hyperarid","Arid","Semi-arid","Dry subhumid")]), "source" = c("mean","sd")) %>%
  select(c("source","Hyperarid","Arid","Semi-arid","Dry subhumid","Sum drylands","Humid","Cold","NA"))


tab <- cmip6 %>% subset(period == "1970_2000" & !Continent %in% c("SOUTHERN","PACIFIC","ATLANTIC","INDIAN","ARCTIC")) %>%
  group_by(source, cat.AI) %>%
  summarise(count = n()) %>%
  ungroup() %>% group_by(source) %>% mutate(percent = round(count/sum(count)*100, 1), count = NULL) %>%
  reshape2::dcast(source~cat.AI) %>%
  mutate("Sum drylands" = rowSums(.[c("Hyperarid","Arid","Semi-arid","Dry subhumid")])) %>%
  select(c("source","Hyperarid","Arid","Semi-arid","Dry subhumid","Sum drylands","Humid","Cold","NA")) %>% 
  rbind(sdmm)


knitr::kable(tab, digits = 2, escape = F)  %>%
  kable_styling(bootstrap_options = "bordered") %>% 
  column_spec(c(6,9), italic = T, include_thead = T) %>% row_spec(c(14,15), bold = T) 
source Hyperarid Arid Semi-arid Dry subhumid Sum drylands Humid Cold NA
CAS-ESM2 3.6 6.0 9.2 4.4 23.2 26.0 48.2 2.6
CESM 3.7 7.4 9.8 3.6 24.5 24.3 48.5 2.6
CMCC 3.6 5.2 7.0 3.8 19.6 29.4 48.5 2.6
CMCC-ESM2 4.5 5.5 5.3 1.8 17.1 17.0 63.3 2.6
CNRM 4.0 8.5 7.9 4.5 24.9 26.6 45.9 2.6
EC-Earth3 5.9 6.6 7.5 3.1 23.1 24.8 49.6 2.6
FGOALS 4.1 7.6 7.0 3.4 22.1 17.5 57.9 2.6
GFDL-ESM4 4.0 6.2 6.2 2.8 19.2 24.6 53.6 2.6
INM 3.1 5.9 9.2 4.0 22.2 27.9 47.4 2.6
INM-CM5 2.3 5.9 8.4 3.9 20.5 29.9 47.0 2.6
MPI 6.0 7.7 7.1 3.0 23.8 23.7 49.9 2.6
MRI 4.3 7.5 6.4 2.7 20.9 27.0 49.5 2.6
NorESM-2-MM 3.6 7.0 11.9 3.9 26.4 23.3 47.7 2.6
mean 4.1 6.7 7.9 3.5 22.2 24.8 50.5 2.6
sd 1.0 1.0 1.8 0.8 4.6 3.9 5.0 0.0

3.3 1985-2010

map_list <- list()

for(i in unique(cmip6$source)){
g <- ggplot(data = subset(cmip6, period == "1985_2015" & source == i)) + geom_raster(aes(x=lon, y = lat,  fill = cat.AI))+
  scale_fill_manual(values = col.cat, na.translate = F)+
  labs(title = paste(i, "1985-2010", sep = ", "), fill = "")+
  theme_void()
map_list[[i]] <- g
}

ggpubr::ggarrange(plotlist = map_list, ncol = 3, nrow = 5, common.legend = T, legend = "bottom")


sdmm <- cmip6 %>% subset(period == "1985_2015" & !Continent %in% c("SOUTHERN","PACIFIC","ATLANTIC","INDIAN","ARCTIC")) %>%
  group_by(source, cat.AI) %>%
  summarise(count = n()) %>%
  ungroup() %>% group_by(source) %>% mutate(percent = round(count/sum(count)*100, 1), count = NULL) %>%
  ungroup() %>% group_by(cat.AI) %>% summarise(mean = round(mean(percent, na.rm = T),1), sd = round(sd(percent, na.rm = T),1)) %>%
  t() %>% as.data.frame() %>% setNames(c(.[1,1:6], "NA")) %>% .[-1, ] %>% sapply(as.numeric) %>% as.data.frame() %>%
  mutate("Sum drylands" = rowSums(.[c("Hyperarid","Arid","Semi-arid","Dry subhumid")]), "source" = c("mean","sd")) %>%
  select(c("source","Hyperarid","Arid","Semi-arid","Dry subhumid","Sum drylands","Humid","Cold","NA"))


tab <- cmip6 %>% subset(period == "1985_2015" & !Continent %in% c("SOUTHERN","PACIFIC","ATLANTIC","INDIAN","ARCTIC")) %>%
  group_by(source, cat.AI) %>%
  summarise(count = n()) %>%
  ungroup() %>% group_by(source) %>% mutate(percent = round(count/sum(count)*100, 1), count = NULL) %>%
  reshape2::dcast(source~cat.AI) %>%
  mutate("Sum drylands" = rowSums(.[c("Hyperarid","Arid","Semi-arid","Dry subhumid")])) %>%
  select(c("source","Hyperarid","Arid","Semi-arid","Dry subhumid","Sum drylands","Humid","Cold","NA")) %>% 
  rbind(sdmm)


knitr::kable(tab, digits = 2, escape = F)  %>%
  kable_styling(bootstrap_options = "bordered") %>% 
  column_spec(c(6,9), italic = T, include_thead = T) %>% row_spec(c(14,15), bold = T) 
source Hyperarid Arid Semi-arid Dry subhumid Sum drylands Humid Cold NA
CAS-ESM2 3.7 5.9 9.6 4.6 23.8 25.9 47.7 2.6
CESM 3.3 7.5 10.3 3.7 24.8 24.6 47.8 2.6
CMCC 3.6 5.3 7.2 4.0 20.1 29.8 47.4 2.6
CMCC-ESM2 4.3 5.9 5.4 1.7 17.3 17.1 63.0 2.6
CNRM 4.0 8.4 7.9 4.3 24.6 27.3 45.5 2.6
EC-Earth3 5.8 6.8 7.4 3.1 23.1 25.6 48.8 2.6
FGOALS 4.0 7.9 7.2 3.4 22.5 17.6 57.3 2.6
GFDL-ESM4 4.1 6.3 6.3 2.7 19.4 25.4 52.6 2.6
INM 2.8 5.4 7.9 3.6 19.7 25.4 52.3 2.6
INM-CM5 2.4 5.8 8.3 3.8 20.3 28.3 48.8 2.6
MPI 6.1 7.8 7.2 3.1 24.2 23.7 49.6 2.6
MRI 4.3 7.5 6.3 2.6 20.7 26.7 50.0 2.6
NorESM-2-MM 3.3 6.9 11.1 3.9 25.2 21.1 51.1 2.6
mean 4.0 6.7 7.9 3.4 22.0 24.5 50.9 2.6
sd 1.0 1.0 1.6 0.8 4.4 3.8 4.7 0.0

3.4 SSP 2-4.5

3.4.1 2030-2060

map_list <- list()

for(i in unique(cmip6$source)){
g <- ggplot(data = subset(cmip6, period == "2030_2060" & model == "SSP245" & source == i)) + geom_raster(aes(x=lon, y = lat,  fill = cat.AI))+
  scale_fill_manual(values = col.cat, na.translate = F)+
  labs(title = paste(i, "2030-2060", sep = ", "), fill = "")+
  theme_void()
map_list[[i]] <- g
}

ggpubr::ggarrange(plotlist = map_list, ncol = 3, nrow = 5, common.legend = T, legend = "bottom")


sdmm <- cmip6 %>% subset(period == "2030_2060" & model == "SSP245" &!Continent %in% c("SOUTHERN","PACIFIC","ATLANTIC","INDIAN","ARCTIC")) %>%
  group_by(source, cat.AI) %>%
  summarise(count = n()) %>%
  ungroup() %>% group_by(source) %>% mutate(percent = round(count/sum(count)*100, 1), count = NULL) %>%
  ungroup() %>% group_by(cat.AI) %>% summarise(mean = round(mean(percent, na.rm = T),1), sd = round(sd(percent, na.rm = T),1)) %>%
  t() %>% as.data.frame() %>% setNames(c(.[1,1:6], "NA")) %>% .[-1, ] %>% sapply(as.numeric) %>% as.data.frame() %>%
  mutate("Sum drylands" = rowSums(.[c("Hyperarid","Arid","Semi-arid","Dry subhumid")]), "source" = c("mean","sd")) %>%
  select(c("source","Hyperarid","Arid","Semi-arid","Dry subhumid","Sum drylands","Humid","Cold","NA"))

tab <- cmip6 %>% subset(period == "2030_2060" & model == "SSP245" & !Continent %in% c("SOUTHERN","PACIFIC","ATLANTIC","INDIAN","ARCTIC")) %>%
  group_by(source, cat.AI) %>%
  summarise(count = n()) %>%
  ungroup() %>% group_by(source) %>% mutate(percent = round(count/sum(count)*100, 1), count = NULL) %>%
  reshape2::dcast(source~cat.AI) %>%
  mutate("Sum drylands" = rowSums(.[c("Hyperarid","Arid","Semi-arid","Dry subhumid")])) %>%
  select(c("source","Hyperarid","Arid","Semi-arid","Dry subhumid","Sum drylands","Humid","Cold","NA")) %>% 
  rbind(sdmm)

knitr::kable(tab, digits = 2, escape = F)  %>%
  kable_styling(bootstrap_options = "bordered") %>% 
  column_spec(c(6,9), italic = T, include_thead = T) %>% row_spec(c(14,15), bold = T) 
source Hyperarid Arid Semi-arid Dry subhumid Sum drylands Humid Cold NA
CAS-ESM2 3.5 6.4 10.2 4.6 24.7 26.5 46.2 2.6
CESM 3.3 8.6 10.6 3.9 26.4 24.8 46.2 2.6
CMCC 3.1 5.9 7.6 4.2 20.8 30.8 45.8 2.6
CMCC-ESM2 4.2 6.3 5.5 2.0 18.0 17.6 61.7 2.6
CNRM 4.2 8.8 8.4 4.7 26.1 27.7 43.6 2.6
EC-Earth3 5.2 6.4 7.7 3.1 22.4 25.3 49.7 2.6
FGOALS 4.8 9.3 12.9 5.4 32.4 21.1 44.0 2.6
GFDL-ESM4 3.8 7.1 6.6 3.1 20.6 25.7 51.3 2.6
INM 3.2 5.8 9.6 4.1 22.7 28.1 46.5 2.6
INM-CM5 2.5 6.0 8.5 3.8 20.8 30.0 46.7 2.6
MPI 6.2 8.3 7.7 3.1 25.3 24.5 47.6 2.6
MRI 4.3 7.8 6.5 2.8 21.4 27.8 48.1 2.6
NorESM-2-MM 3.7 8.2 11.7 3.9 27.5 23.3 46.5 2.6
mean 4.0 7.3 8.7 3.7 23.7 25.6 48.0 2.6
sd 1.0 1.2 2.2 0.9 5.3 3.6 4.6 0.0

3.4.2 2070-2100

map_list <- list()

for(i in unique(cmip6$source)){
g <- ggplot(data = subset(cmip6, period == "2070_2100" & model == "SSP245" & source == i)) + geom_raster(aes(x=lon, y = lat,  fill = cat.AI))+
  scale_fill_manual(values = col.cat, na.translate = F)+
  labs(title = paste(i, "2070-2100", sep = ", "), fill = "")+
  theme_void()
map_list[[i]] <- g
}

ggpubr::ggarrange(plotlist = map_list, ncol = 3, nrow = 5, common.legend = T, legend = "bottom")

sdmm <- cmip6 %>% subset(period == "2070_2100" & model == "SSP245" &!Continent %in% c("SOUTHERN","PACIFIC","ATLANTIC","INDIAN","ARCTIC")) %>%
  group_by(source, cat.AI) %>%
  summarise(count = n()) %>%
  ungroup() %>% group_by(source) %>% mutate(percent = round(count/sum(count)*100, 1), count = NULL) %>%
  ungroup() %>% group_by(cat.AI) %>% summarise(mean = round(mean(percent, na.rm = T),1), sd = round(sd(percent, na.rm = T),1)) %>%
  t() %>% as.data.frame() %>% setNames(c(.[1,1:6], "NA")) %>% .[-1, ] %>% sapply(as.numeric) %>% as.data.frame() %>%
  mutate("Sum drylands" = rowSums(.[c("Hyperarid","Arid","Semi-arid","Dry subhumid")]), "source" = c("mean","sd")) %>%
  select(c("source","Hyperarid","Arid","Semi-arid","Dry subhumid","Sum drylands","Humid","Cold","NA"))

tab <- cmip6 %>% subset(period == "2070_2100" & model == "SSP245" & !Continent %in% c("SOUTHERN","PACIFIC","ATLANTIC","INDIAN","ARCTIC")) %>%
  group_by(source, cat.AI) %>%
  summarise(count = n()) %>%
  ungroup() %>% group_by(source) %>% mutate(percent = round(count/sum(count)*100, 1), count = NULL) %>%
  reshape2::dcast(source~cat.AI) %>%
  mutate("Sum drylands" = rowSums(.[c("Hyperarid","Arid","Semi-arid","Dry subhumid")])) %>%
  select(c("source","Hyperarid","Arid","Semi-arid","Dry subhumid","Sum drylands","Humid","Cold","NA")) %>% 
  rbind(sdmm)

knitr::kable(tab, digits = 2, escape = F)  %>%
  kable_styling(bootstrap_options = "bordered") %>% 
  column_spec(c(6,9), italic = T, include_thead = T) %>% row_spec(c(14,15), bold = T) 
source Hyperarid Arid Semi-arid Dry subhumid Sum drylands Humid Cold NA
CAS-ESM2 3.3 7.3 10.4 5.1 26.1 26.6 44.8 2.6
CESM 4.2 8.1 10.7 3.7 26.7 25.7 44.9 2.6
CMCC 3.0 5.6 8.5 4.5 21.6 32.4 43.4 2.6
CMCC-ESM2 4.3 6.6 5.9 1.9 18.7 18.7 60.0 2.6
CNRM 4.4 9.0 8.6 4.7 26.7 28.5 42.2 2.6
EC-Earth3 5.3 6.4 7.7 3.0 22.4 26.0 49.1 2.6
FGOALS 4.8 9.8 12.6 5.6 32.8 21.1 43.5 2.6
GFDL-ESM4 4.1 6.7 6.8 3.1 20.7 26.8 50.0 2.6
INM 3.3 5.7 9.8 4.1 22.9 28.3 46.3 2.6
INM-CM5 2.6 6.6 7.8 4.1 21.1 30.3 46.0 2.6
MPI 6.2 8.3 7.7 3.1 25.3 24.5 47.6 2.6
MRI 4.5 7.6 6.7 2.8 21.6 28.4 47.4 2.6
NorESM-2-MM 4.1 8.2 11.8 4.1 28.2 23.7 45.6 2.6
mean 4.2 7.4 8.8 3.8 24.2 26.2 47.0 2.6
sd 1.0 1.3 2.1 1.0 5.4 3.7 4.5 0.0

3.5 SSP 3-7.0

3.5.1 2030-2060

map_list <- list()

for(i in unique(cmip6$source)){
g <- ggplot(data = subset(cmip6, period == "2030_2060" & model == "SSP370" & source == i)) + geom_raster(aes(x=lon, y = lat,  fill = cat.AI))+
  scale_fill_manual(values = col.cat, na.translate = F)+
  labs(title = paste(i, "2030-2060", sep = ", "), fill = "")+
  theme_void()
map_list[[i]] <- g
}

ggpubr::ggarrange(plotlist = map_list, ncol = 3, nrow = 5, common.legend = T, legend = "bottom")

sdmm <- cmip6 %>% subset(period == "2030_2060" & model == "SSP370" &!Continent %in% c("SOUTHERN","PACIFIC","ATLANTIC","INDIAN","ARCTIC")) %>%
  group_by(source, cat.AI) %>%
  summarise(count = n()) %>%
  ungroup() %>% group_by(source) %>% mutate(percent = round(count/sum(count)*100, 1), count = NULL) %>%
  ungroup() %>% group_by(cat.AI) %>% summarise(mean = round(mean(percent, na.rm = T),1), sd = round(sd(percent, na.rm = T),1)) %>%
  t() %>% as.data.frame() %>% setNames(c(.[1,1:6], "NA")) %>% .[-1, ] %>% sapply(as.numeric) %>% as.data.frame() %>%
  mutate("Sum drylands" = rowSums(.[c("Hyperarid","Arid","Semi-arid","Dry subhumid")]), "source" = c("mean","sd")) %>%
  select(c("source","Hyperarid","Arid","Semi-arid","Dry subhumid","Sum drylands","Humid","Cold","NA"))

tab <- cmip6 %>% subset(period == "2030_2060" & model == "SSP370" & !Continent %in% c("SOUTHERN","PACIFIC","ATLANTIC","INDIAN","ARCTIC")) %>%
  group_by(source, cat.AI) %>%
  summarise(count = n()) %>%
  ungroup() %>% group_by(source) %>% mutate(percent = round(count/sum(count)*100, 1), count = NULL) %>%
  reshape2::dcast(source~cat.AI) %>%
  mutate("Sum drylands" = rowSums(.[c("Hyperarid","Arid","Semi-arid","Dry subhumid")])) %>%
  select(c("source","Hyperarid","Arid","Semi-arid","Dry subhumid","Sum drylands","Humid","Cold","NA")) %>% 
  rbind(sdmm)

knitr::kable(tab, digits = 2, escape = F)  %>%
  kable_styling(bootstrap_options = "bordered") %>% 
  column_spec(c(6,9), italic = T, include_thead = T) %>% row_spec(c(14,15), bold = T) 
source Hyperarid Arid Semi-arid Dry subhumid Sum drylands Humid Cold NA
CAS-ESM2 3.4 6.7 9.9 4.8 24.8 26.0 46.6 2.6
CESM 3.6 7.9 10.8 3.7 26.0 24.8 46.4 2.6
CMCC 2.9 5.8 7.9 4.1 20.7 30.7 46.0 2.6
CMCC-ESM2 2.3 5.8 6.2 2.5 16.8 18.7 61.8 2.6
CNRM 4.3 9.0 8.9 5.0 27.2 27.6 42.6 2.6
EC-Earth3 5.5 6.8 8.0 3.3 23.6 26.8 47.0 2.6
FGOALS 4.2 8.3 8.3 3.7 24.5 19.2 53.8 2.6
GFDL-ESM4 4.4 6.6 6.9 2.9 20.8 25.0 51.8 2.6
INM 3.2 5.8 9.4 4.1 22.5 28.0 46.9 2.6
INM-CM5 2.4 6.2 8.4 3.9 20.9 30.1 46.4 2.6
MPI 6.1 8.5 7.6 3.1 25.3 25.3 46.8 2.6
MRI 4.5 7.5 6.5 2.5 21.0 28.0 48.3 2.6
NorESM-2-MM 3.8 7.6 12.5 4.0 27.9 23.1 46.4 2.6
mean 3.9 7.1 8.6 3.7 23.3 25.6 48.5 2.6
sd 1.1 1.1 1.8 0.8 4.8 3.6 4.8 0.0

3.5.2 2070-2100

map_list <- list()

for(i in unique(cmip6$source)){
g <- ggplot(data = subset(cmip6, period == "2070_2100" & model == "SSP370" & source == i)) + geom_raster(aes(x=lon, y = lat,  fill = cat.AI))+
  scale_fill_manual(values = col.cat, na.translate = F)+
  labs(title = paste(i, "2070-2100", sep = ", "), fill = "")+
  theme_void()
map_list[[i]] <- g
}

ggpubr::ggarrange(plotlist = map_list, ncol = 3, nrow = 5, common.legend = T, legend = "bottom")

sdmm <- cmip6 %>% subset(period == "2070_2100" & model == "SSP370" &!Continent %in% c("SOUTHERN","PACIFIC","ATLANTIC","INDIAN","ARCTIC")) %>%
  group_by(source, cat.AI) %>%
  summarise(count = n()) %>%
  ungroup() %>% group_by(source) %>% mutate(percent = round(count/sum(count)*100, 1), count = NULL) %>%
  ungroup() %>% group_by(cat.AI) %>% summarise(mean = round(mean(percent, na.rm = T),1), sd = round(sd(percent, na.rm = T),1)) %>%
  t() %>% as.data.frame() %>% setNames(c(.[1,1:6], "NA")) %>% .[-1, ] %>% sapply(as.numeric) %>% as.data.frame() %>%
  mutate("Sum drylands" = rowSums(.[c("Hyperarid","Arid","Semi-arid","Dry subhumid")]), "source" = c("mean","sd")) %>%
  select(c("source","Hyperarid","Arid","Semi-arid","Dry subhumid","Sum drylands","Humid","Cold","NA"))

tab <- cmip6 %>% subset(period == "2070_2100" & model == "SSP370" & !Continent %in% c("SOUTHERN","PACIFIC","ATLANTIC","INDIAN","ARCTIC")) %>%
  group_by(source, cat.AI) %>%
  summarise(count = n()) %>%
  ungroup() %>% group_by(source) %>% mutate(percent = round(count/sum(count)*100, 1), count = NULL) %>%
  reshape2::dcast(source~cat.AI) %>%
  mutate("Sum drylands" = rowSums(.[c("Hyperarid","Arid","Semi-arid","Dry subhumid")])) %>%
  select(c("source","Hyperarid","Arid","Semi-arid","Dry subhumid","Sum drylands","Humid","Cold","NA")) %>% 
  rbind(sdmm)

knitr::kable(tab, digits = 2, escape = F)  %>%
  kable_styling(bootstrap_options = "bordered") %>% 
  column_spec(c(6,9), italic = T, include_thead = T) %>% row_spec(c(14,15), bold = T) 
source Hyperarid Arid Semi-arid Dry subhumid Sum drylands Humid Cold NA
CAS-ESM2 3.8 7.3 10.7 4.8 26.6 26.0 44.9 2.6
CESM 4.2 8.5 10.8 4.0 27.5 26.0 43.9 2.6
CMCC 3.6 6.3 8.7 5.1 23.7 30.7 43.0 2.6
CMCC-ESM2 4.8 6.9 5.7 2.1 19.5 18.0 59.9 2.6
CNRM 5.1 9.0 9.2 4.7 28.0 27.3 42.2 2.6
EC-Earth3 5.3 6.9 8.6 3.3 24.1 28.1 45.3 2.6
FGOALS 4.7 9.3 9.2 3.0 26.2 19.5 51.8 2.6
GFDL-ESM4 5.2 5.9 7.6 3.3 22.0 25.7 49.7 2.6
INM 4.2 5.7 10.2 4.3 24.4 27.3 45.7 2.6
INM-CM5 2.7 7.2 9.8 4.3 24.0 28.1 45.3 2.6
MPI 6.1 8.5 7.6 3.1 25.3 25.3 46.8 2.6
MRI 5.0 8.3 6.9 2.9 23.1 27.2 47.2 2.6
NorESM-2-MM 4.1 8.2 12.2 4.1 28.6 23.5 45.3 2.6
mean 4.5 7.5 9.0 3.8 24.8 25.6 47.0 2.6
sd 0.9 1.2 1.8 0.9 4.8 3.5 4.7 0.0

3.6 SSP 5-8.5

3.6.1 2030-2060

map_list <- list()

for(i in unique(cmip6$source)){
g <- ggplot(data = subset(cmip6, period == "2030_2060" & model == "SSP585" & source == i)) + geom_raster(aes(x=lon, y = lat,  fill = cat.AI))+
  scale_fill_manual(values = col.cat, na.translate = F)+
  labs(title = paste(i, "2030-2060", sep = ", "), fill = "")+
  theme_void()
map_list[[i]] <- g
}

ggpubr::ggarrange(plotlist = map_list, ncol = 3, nrow = 5, common.legend = T, legend = "bottom")

sdmm <- cmip6 %>% subset(period == "2030_2060" & model == "SSP585" &!Continent %in% c("SOUTHERN","PACIFIC","ATLANTIC","INDIAN","ARCTIC")) %>%
  group_by(source, cat.AI) %>%
  summarise(count = n()) %>%
  ungroup() %>% group_by(source) %>% mutate(percent = round(count/sum(count)*100, 1), count = NULL) %>%
  ungroup() %>% group_by(cat.AI) %>% summarise(mean = round(mean(percent, na.rm = T),1), sd = round(sd(percent, na.rm = T),1)) %>%
  t() %>% as.data.frame() %>% setNames(c(.[1,1:6], "NA")) %>% .[-1, ] %>% sapply(as.numeric) %>% as.data.frame() %>%
  mutate("Sum drylands" = rowSums(.[c("Hyperarid","Arid","Semi-arid","Dry subhumid")]), "source" = c("mean","sd")) %>%
  select(c("source","Hyperarid","Arid","Semi-arid","Dry subhumid","Sum drylands","Humid","Cold","NA"))

tab <- cmip6 %>% subset(period == "2030_2060" & model == "SSP585" & !Continent %in% c("SOUTHERN","PACIFIC","ATLANTIC","INDIAN","ARCTIC")) %>%
  group_by(source, cat.AI) %>%
  summarise(count = n()) %>%
  ungroup() %>% group_by(source) %>% mutate(percent = round(count/sum(count)*100, 1), count = NULL) %>%
  reshape2::dcast(source~cat.AI) %>%
  mutate("Sum drylands" = rowSums(.[c("Hyperarid","Arid","Semi-arid","Dry subhumid")])) %>%
  select(c("source","Hyperarid","Arid","Semi-arid","Dry subhumid","Sum drylands","Humid","Cold","NA")) %>% 
  rbind(sdmm)

knitr::kable(tab, digits = 2, escape = F)  %>%
  kable_styling(bootstrap_options = "bordered") %>% 
  column_spec(c(6,9), italic = T, include_thead = T) %>% row_spec(c(14,15), bold = T) 
source Hyperarid Arid Semi-arid Dry subhumid Sum drylands Humid Cold NA
CAS-ESM2 3.4 6.4 10.5 5.2 25.5 26.2 45.8 2.6
CESM 4.0 8.0 10.9 3.6 26.5 25.0 45.9 2.6
CMCC 3.0 5.6 8.0 4.5 21.1 31.2 45.0 2.6
CMCC-ESM2 4.5 6.5 5.6 1.7 18.3 17.7 61.4 2.6
CNRM 4.3 9.2 8.6 4.8 26.9 27.8 42.6 2.6
EC-Earth3 5.4 6.6 8.2 3.2 23.4 27.0 47.0 2.6
FGOALS 4.8 9.4 12.6 5.4 32.2 21.4 43.9 2.6
GFDL-ESM4 4.3 6.6 6.8 3.3 21.0 25.3 51.2 2.6
INM 3.2 5.8 9.7 4.1 22.8 28.3 46.2 2.6
INM-CM5 2.5 6.0 8.6 4.0 21.1 30.3 46.0 2.6
MPI 6.0 8.7 7.7 3.1 25.5 25.7 46.2 2.6
MRI 4.2 7.7 6.7 2.8 21.4 28.4 47.6 2.6
NorESM-2-MM 3.8 7.9 12.2 4.1 28.0 23.1 46.2 2.6
mean 4.1 7.3 8.9 3.8 24.1 26.0 47.3 2.6
sd 1.0 1.3 2.1 1.0 5.4 3.7 4.7 0.0

3.6.2 2070-2100

map_list <- list()

for(i in unique(cmip6$source)){
g <- ggplot(data = subset(cmip6, period == "2070_2100" & model == "SSP585" & source == i)) + geom_raster(aes(x=lon, y = lat,  fill = cat.AI))+
  scale_fill_manual(values = col.cat, na.translate = F)+
  labs(title = paste(i, "2070-2100", sep = ", "), fill = "")+
  theme_void()
map_list[[i]] <- g
}

ggpubr::ggarrange(plotlist = map_list, ncol = 3, nrow = 5, common.legend = T, legend = "bottom")

sdmm <- cmip6 %>% subset(period == "2070_2100" & model == "SSP585" &!Continent %in% c("SOUTHERN","PACIFIC","ATLANTIC","INDIAN","ARCTIC")) %>%
  group_by(source, cat.AI) %>%
  summarise(count = n()) %>%
  ungroup() %>% group_by(source) %>% mutate(percent = round(count/sum(count)*100, 1), count = NULL) %>%
  ungroup() %>% group_by(cat.AI) %>% summarise(mean = round(mean(percent, na.rm = T),1), sd = round(sd(percent, na.rm = T),1)) %>%
  t() %>% as.data.frame() %>% setNames(c(.[1,1:6], "NA")) %>% .[-1, ] %>% sapply(as.numeric) %>% as.data.frame() %>%
  mutate("Sum drylands" = rowSums(.[c("Hyperarid","Arid","Semi-arid","Dry subhumid")]), "source" = c("mean","sd")) %>%
  select(c("source","Hyperarid","Arid","Semi-arid","Dry subhumid","Sum drylands","Humid","Cold","NA"))

tab <- cmip6 %>% subset(period == "2070_2100" & model == "SSP585" & !Continent %in% c("SOUTHERN","PACIFIC","ATLANTIC","INDIAN","ARCTIC")) %>%
  group_by(source, cat.AI) %>%
  summarise(count = n()) %>%
  ungroup() %>% group_by(source) %>% mutate(percent = round(count/sum(count)*100, 1), count = NULL) %>%
  reshape2::dcast(source~cat.AI) %>%
  mutate("Sum drylands" = rowSums(.[c("Hyperarid","Arid","Semi-arid","Dry subhumid")])) %>%
  select(c("source","Hyperarid","Arid","Semi-arid","Dry subhumid","Sum drylands","Humid","Cold","NA")) %>% 
  rbind(sdmm)

knitr::kable(tab, digits = 2, escape = F)  %>%
  kable_styling(bootstrap_options = "bordered") %>% 
  column_spec(c(6,9), italic = T, include_thead = T) %>% row_spec(c(13,14), bold = T) 
source Hyperarid Arid Semi-arid Dry subhumid Sum drylands Humid Cold NA
CAS-ESM2 4.3 7.5 11.1 4.5 27.4 26.1 43.9 2.6
CMCC 3.1 6.5 9.4 4.6 23.6 32.5 41.3 2.6
CMCC-ESM2 3.9 7.3 6.2 2.0 19.4 19.5 58.5 2.6
CNRM 4.2 9.4 8.9 4.4 26.9 28.5 42.0 2.6
EC-Earth3 5.4 6.7 9.1 3.4 24.6 28.2 44.6 2.6
FGOALS 10.8 10.4 12.7 4.7 38.6 16.9 41.8 2.6
GFDL-ESM4 4.5 6.9 7.5 3.3 22.2 26.2 49.0 2.6
INM 3.1 6.1 10.3 4.1 23.6 29.0 44.8 2.6
INM-CM5 2.7 6.8 8.3 4.2 22.0 30.7 44.6 2.6
MPI 6.1 8.6 7.7 3.3 25.7 25.6 46.2 2.6
MRI 4.9 8.0 7.4 2.8 23.1 27.9 46.4 2.6
NorESM-2-MM 4.4 8.9 12.1 4.5 29.9 23.9 43.5 2.6
mean 4.8 7.8 9.2 3.8 25.6 26.2 45.5 2.6
sd 2.1 1.3 2.0 0.8 6.2 4.4 4.6 0.0

4 Agreement between models

4.1 Summary dataframe

 getAIref <- function(i) {
   AIrefi = subset(cmip6s, lat == cmip6s$lat[i] & lon == cmip6s$lon[i] & period =="1970_2000") %>% pull(AI.mean) 
   return(AIrefi)
 }
 
 AI.refbymodel <- sapply(as.numeric(rownames(cmip6)), FUN = getAIref)
 saveRDS(AI.ref.bymodel, "AI.ref.bymodel.rds")
 
 
 cmip6ref <- cmip6 %>% select(c("lon","lat","model","AI")) %>% subset(period = "1970-2000")  %>% setNames(c("lon","lat","model","AI.ref"))

 test <- merge(head(cmip6, 5000), cmip6ref, by = c("lon","lat","model"))
 
 
cmip6s <- cmip6 %>% 
  group_by(lon,lat,Continent, Type, Name, Acronym, lm, model, period, z) %>% 
   dplyr::summarise(t.mean = mean(t, na.rm = T), t.sd = sd(t, na.rm = T), # t in °C
                    pr.mean = mean(spr, na.rm = T) , pr.sd = sd(spr, na.rm = T),  # pr in mm/y
                   sfcWind.mean = mean(sfcWind, na.rm = T), sfcWind.sd = sd(sfcWind, na.rm = T),
                   Rn.mean = mean(Rn, na.rm = T), Rn.sd = sd(Rn, na.rm = T), # in MJ/m2/day
                   ea.mean = mean(ea, na.rm = T), ea.sd = sd(ea, na.rm = T), # in kPa
                   ET0 = mean(sET0, na.rm = T), ET0.sd = sd(sET0, na.rm = T), # in mm/y
                   AI.mean = mean(AI, na.rm = T), AI.sd = sd(AI, na.rm = T),
                   hyperarid = sum(cat.AI == "Hyperarid"),
                   arid = sum(cat.AI == "Arid"),
                   semiarid = sum(cat.AI == "Semi-arid"),
                  drysubhumid = sum(cat.AI == "Dry subhumid") ,
                   humid = sum(cat.AI == "Humid"),
                   cold = sum(cat.AI == "Cold"),
                   na = sum(is.na(cat.AI)),
                  nb.models = n(),
                  nb.maj = max(hyperarid,arid,semiarid,drysubhumid,humid,cold,na),
                  prop.maj = nb.maj/nb.models,
                   ) %>% ungroup() %>% as.data.frame()

cmip6s$cat.maj <- colnames(select(cmip6s, c("hyperarid","arid",'semiarid',"drysubhumid",'humid',"cold","na")))[max.col(select(cmip6s, c("hyperarid","arid",'semiarid',"drysubhumid",'humid',"cold","na")),ties.method = "first")]

write.table(cmip6s, "cmip6s.txt")
cmip6s <- read.table("cmip6s.txt")

breaks.unesco <- c(-Inf,0,0.03,0.2,0.5,0.65,Inf)
cat.unesco <- c("(0,0.03]"= "Hyperarid", "(0.03,0.2]" = "Arid", "(0.2,0.5]" = "Semi-arid", "(0.5,0.65]" = "Dry subhumid","(0.65, Inf]" = "Humid", "(-Inf,0]" = "Cold")

cmip6s$cat.AI <- cmip6s$AI.mean %>% cut(breaks = breaks.unesco) %>% revalue(cat.unesco)
cmip6s$cat.AI[which(cmip6s$ET0 < 400)] <- "Cold"

# getAIref <- function(i) {
#   AIrefi = subset(cmip6s, lat == cmip6s$lat[i] & lon == cmip6s$lon[i] & period =="1970_2000") %>% pull(AI.mean) 
#   return(AIrefi)
# }
# 
# AI.ref <- sapply(as.numeric(rownames(cmip6s)), FUN = getAIref)
# saveRDS(AI.ref, "AI.ref.rds")


cmip6s$AI.ref <- readRDS("AI.ref.rds") 

# getcatAIref <- function(i) {
#   catAIrefi = subset(cmip6s, lat == cmip6s$lat[i] & lon == cmip6s$lon[i] & period =="1970_2000") %>% pull(cat.AI) 
#   return(catAIrefi)
# }
# 
# catAIref.vect <- sapply(as.numeric(rownames(cmip6s)), FUN = getcatAIref)
# saveRDS(catAIref, "cat.AI.ref.rds")


cmip6s$catAIref <- readRDS("catAIref.vect.rds")

# getcatmajref <- function(i) {
#   catmajrefi = subset(cmip6s, lat == cmip6s$lat[i] & lon == cmip6s$lon[i] & period =="1970_2000") %>% pull(cat.maj) 
#   return(catmajrefi)
# }
# 
# cmip6.catmajref <- sapply(as.numeric(rownames(cmip6s)), FUN = getcatmajref)
# saveRDS(cmip6.catmajref, "cmip6.catmajref.rds")

cmip6s$catmajref <- readRDS("cmip6.catmajref.rds")

cmip6s$anomalies <- with(cmip6s, AI.mean - AI.ref)

cmip6s$same.catAI <- with(cmip6s, ifelse(cat.maj == cat.AI, "same", "diff"))

write.table(cmip6s, "cmip6s2.txt")
cmip6s <- read.table("cmip6s2.txt")

# attributes a change from the studied period compared to the reference period 1970-2000. Read as: grid cell x is humid in 2030-2060 and Arid in 1970-2000, so it is WETTER

#cmip6s$change <-  with(cmip6s, paste(catAIref, cat.AI, collapse = " ", sep = " to "))

cmip6s$dryer <- with(cmip6s, ifelse(catAIref == "Arid" & cat.AI %in% c("Cold","Humid","Dry subhumid","Semi-arid"), "wetter", 
                                ifelse(catAIref == "Arid" & cat.AI == "Hyperarid", "dryer",
                                ifelse(catAIref == "Semi-arid" & cat.AI %in% c("Cold","Humid","Dry subhumid"), "wetter",
                                ifelse(catAIref == "Semi-arid" & cat.AI %in% c("Hyperarid","Arid"), "dryer",
                                ifelse(catAIref == "Dry subhumid" & cat.AI %in% c("Cold","Humid"), "wetter",
                                ifelse(catAIref == "Dry subhumid" & cat.AI %in% c("Semi-arid","Arid","Hyperarid"), "dryer",
                                ifelse(catAIref == "Humid" & cat.AI == "Cold","wetter",
                                ifelse(catAIref == "Humid" & cat.AI %in% c("Dry subhumid","Semi-arid","Arid","Hyperarid"), "dryer",
                                ifelse(catAIref == "Cold" & cat.AI %in% c("Humid","Dry subhumid","Semi-arid","Arid","Hyperarid"), "dryer",
                                ifelse(catAIref == "Hyperarid" & cat.AI %in% c("Cold","Humid","Dry subhumid","Semi-arid","Arid"), "wetter",
                                       NA)))))))))))


cmip6s$catmajref <- revalue(cmip6s$catmajref, c("hyperarid" = "Hyperarid", "arid" = "Arid", "semiarid" = "Semi-arid", "drysubhumid" = "Dry subhumid", "humid" = "Humid", "cold" = "Cold"))

cmip6s$cat.maj <- revalue(cmip6s$cat.maj, c("hyperarid" = "Hyperarid", "arid" = "Arid", "semiarid" = "Semi-arid", "drysubhumid" = "Dry subhumid", "humid" = "Humid", "cold" = "Cold"))



cmip6s$dryer.maj <- with(cmip6s, ifelse(catmajref == "Arid" & cat.maj %in% c("Cold","Humid","Dry subhumid","Semi-arid"), "wetter", 
                                ifelse(catmajref == "Arid" & cat.maj == "Hyperarid", "dryer",
                                ifelse(catmajref == "Semi-arid" & cat.maj %in% c("Cold","Humid","Dry subhumid"), "wetter",
                                ifelse(catmajref == "Semi-arid" & cat.maj %in% c("Hyperarid","Arid"), "dryer",
                                ifelse(catmajref == "Dry subhumid" & cat.maj %in% c("Cold","Humid"), "wetter",
                                ifelse(catmajref == "Dry subhumid" & cat.maj %in% c("Semi-arid","Arid","Hyperarid"), "dryer",
                                ifelse(catmajref == "Humid" & cat.maj == "Cold","wetter",
                                ifelse(catmajref == "Humid" & cat.maj %in% c("Dry subhumid","Semi-arid","Arid","Hyperarid"), "dryer",
                                ifelse(catmajref == "Cold" & cat.maj %in% c("Humid","Dry subhumid","Semi-arid","Arid","Hyperarid"), "dryer",
                                ifelse(catmajref == "Hyperarid" & cat.maj %in% c("Cold","Humid","Dry subhumid","Semi-arid","Arid"), "wetter",
                                       NA)))))))))))

4.2 Compare cat mean and cat maj

cat mean = category of aridity obtained by using the multimodel mean AI cat maj = category of aridity obtained by using the category majoritarily obtained in the 13 models

4.2.1 Where are cat mean and cat maj different


cmip6s %>% group_by(model, period) %>% summarise(maj.equal.mean = table(same.catAI)[2], maj.diff.mean = table(same.catAI)[1], prop.same = round(maj.equal.mean/n()*100,1)) %>% knitr::kable(col.names = c("Model","Period","Number of gridcells in which cat.maj = cat.mean", "Number of gridcells in which cat.maj /= cat.mean", "Proportion of cells with the same category (%)")) %>% kableExtra::kable_styling(bootstrap_options = "bordered")
Model Period Number of gridcells in which cat.maj = cat.mean Number of gridcells in which cat.maj /= cat.mean Proportion of cells with the same category (%)
SSP245 2030_2060 19884 1798 89.3
SSP245 2070_2100 19890 1792 89.3
SSP370 2030_2060 19988 1694 89.8
SSP370 2070_2100 19911 1771 89.4
SSP585 2030_2060 19799 1883 88.9
SSP585 2070_2100 19796 1886 88.9
historical 1850_1880 19907 1775 89.4
historical 1970_2000 19880 1802 89.3
historical 1985_2015 19936 1746 89.6

cmip6s$cat.AI <- factor(cmip6s$cat.AI, levels =  c("Hyperarid","Arid","Semi-arid","Dry subhumid", "Humid","Cold"))
cmip6s$cat.maj <- factor(cmip6s$cat.maj, levels =  c("Hyperarid","Arid","Semi-arid","Dry subhumid", "Humid","Cold"))

ggplot(subset(cmip6s, cat.AI != "Cold"))+
  geom_col(aes(x= period, y = cat.AI, fill = cat.AI), just = -0.2, width = 0.3)+
  geom_col(aes(x = period, y = cat.maj, fill = cat.maj), just = 1.2, width = 0.3)+
  scale_fill_manual(values = col.cat)+
  labs(fill = "", y ="")+
  facet_grid(rows = vars(model), switch = "y")+
  theme_minimal()+theme(axis.text.y = element_blank())




tab <- rbind(table(cmip6s$cat.AI)/length(cmip6s$cat.AI)*100, table(cmip6s$cat.maj)/length(cmip6s$cat.maj)*100) %>% t() %>% as.data.frame() %>% setNames(c("Cat mean", "Cat maj"))
knitr::kable(tab, digits =2, caption = "Proportion of gridcells in each aridity category") %>% kable_styling(bootstrap_options = "bordered")
Proportion of gridcells in each aridity category
Cat mean Cat maj
Hyperarid 3.51 4.18
Arid 6.25 7.43
Semi-arid 7.63 9.19
Dry subhumid 3.39 0.84
Humid 28.75 28.53
Cold 47.90 47.23
map_list <- list()

for(i in unique(cmip6s$model)){
  df <- subset(cmip6s, model == i)
  for(j in unique(df$period)){
    index <- paste(i, j, sep = "")
    g <- ggplot()+geom_raster(data = subset(df, period == j & same.catAI == "diff"), aes(x = lon, y = lat, fill = cat.AI))+
      borders(colour = "grey60")+
  scale_fill_manual(values =  col.cat, na.translate = F)+
  labs(title = paste(i, j , sep = " "), fill = "")+
  theme_void()+ylim(-55,90)+
  theme(legend.position = "bottom")
 map_list[[index]] <- g
  }
}

col1 <- ggarrange(plotlist = map_list, nrow = 9, ncol = 1, common.legend = T, legend = "bottom") %>% annotate_figure(top = "cat.mean for gridcells in which\ncat.maj and cat.mean are different")

map_list2 <- list()

for(i in unique(cmip6s$model)){
  df <- subset(cmip6s, model == i)
  for(j in unique(df$period)){
    index <- paste(i, j, sep = "")
    g <- ggplot()+geom_raster(data = subset(df, period == j & same.catAI == "diff"), aes(x = lon, y = lat, fill = cat.maj))+
      borders(colour = "grey60")+
  scale_fill_manual(values =  col.cat, na.translate = F)+
  labs(title = paste(i, j , sep = " "), fill = "")+
  theme_void()+ylim(-55,90)+
  theme(legend.position = "bottom")
  map_list2[[index]] <- g
  }
}

col2 <- ggarrange(plotlist = map_list2, nrow = 9, ncol = 1, common.legend = T, legend = "bottom") %>% annotate_figure(top = "cat.maj for gridcells in which\ncat.maj and cat.mean are different")

ggarrange(col1,col2,ncol = 2, common.legend = T)

4.2.2 Plot cat maj and cat mean for reference period

ggpubr::ggarrange(plotlist = list(

  ggplot() + 
  geom_raster(data = subset(cmip6s, period == "1970_2000"), aes(x=lon, y = lat,  fill = cat.maj))+
  geom_point(data = subset(cmip6s, period == "1970_2000" & nb.maj > 10), aes(x =lon, y = lat), shape = "'", size = 1, col = "grey20")+
    scale_fill_manual(values = col.cat)+
    labs(title = "Category chosen in majority by models", fill = "")+
    ylim(-55,90)+
    theme_void(base_size = 15)+
    theme(legend.position = "none"),
  
   ggplot() + 
  geom_raster(data = subset(cmip6s, period == "1970_2000"), aes(x=lon, y = lat,  fill = cat.AI))+
  geom_point(data = subset(cmip6s, period == "1970_2000" & nb.maj > 10), aes(x =lon, y = lat), shape = "'", size = 1, col = "grey20")+
    scale_fill_manual(values = col.cat)+
    labs(title = "Multimodel average categories of AI", fill = "")+
    ylim(-55,90)+
    theme_void(base_size = 15)+
    theme(legend.position = "none")),
  
  ncol = 2)
map_list <- list()

for(i in c("1850_1880","1970_2000","1985_2015")){
g <- ggplot() + geom_raster(data = subset(cmip6s, period == i & model == "historical"), aes(x=lon, y = lat,  fill = cat.maj))+
   geom_point(data = subset(cmip6s, period == i & model == "historical" & nb.maj > 10), aes(x= lon, y = lat), shape = "'", col = "black")+
  scale_fill_manual(values =  col.cat, na.translate = F)+
  labs(title = i, fill = "")+
  theme_void()+ylim(-55,90)+
  theme(legend.position = "bottom")
map_list[[i]] <- g
  }


map_list2 <- list()

for(i in c("1850_1880","1970_2000","1985_2015")){
g <- ggplot() + geom_raster(data = subset(cmip6s, period == i & model == "historical"), aes(x=lon, y = lat,  fill = cat.AI))+
   geom_point(data = subset(cmip6s, period == i & model == "historical" & nb.maj > 10), aes(x= lon, y = lat), shape = "'", col = "black")+
  scale_fill_manual(values =  col.cat, na.translate = F)+
  labs(title = i, fill = "")+
  theme_void()+ylim(-55,90)+
  theme(legend.position = "bottom")
map_list2[[i]] <- g
}


ggarrange(
annotate_figure(ggarrange(plotlist = map_list, nrow = 3, common.legend = T, legend = "bottom"), top = "Majority category among models"),
annotate_figure(ggarrange(plotlist = map_list2, nrow = 3, common.legend = T, legend = "bottom"), top = "Multimodel average category"),
ncol = 2, legend = "bottom")

map_list <- list()

for(i in c("SSP245","SSP370","SSP585")){
  for (j in c("2030_2060","2070_2100")){
index <- paste(i, j, sep = " , ")
g <- ggplot() + geom_raster(data = subset(cmip6s, period == j & model == i), aes(x=lon, y = lat,  fill = cat.maj))+
#   geom_point(data = subset(cmip6s, period == i & model == "historical" & change.cat == 1 & nb.maj > 10), aes(x= lon, y = lat), shape = "'")+
  scale_fill_manual(values = col.cat, na.translate = F)+
  labs(fill = "Cat AI maj", title = paste(i, j, sep = ", "))+
  theme_void()+ylim(-55,90)+
  theme(legend.position = "bottom")
map_list[[index]] <- g
  }}


map_list2 <- list()

for(i in c("SSP245","SSP370","SSP585")){
  for (j in c("2030_2060","2070_2100")){
index <- paste(i, j, sep = " , ")
g <- ggplot() + geom_raster(data = subset(cmip6s, period == j & model == i), aes(x=lon, y = lat,  fill = cat.AI))+
#   geom_point(data = subset(cmip6s, period == i & model == "historical" & change.cat == 1 & nb.maj > 10), aes(x= lon, y = lat), shape = "'")+
  scale_fill_manual(values = col.cat, na.translate = F)+
  labs(fill = "Cat AI mean", title = paste(i, j, sep = ", "))+
  theme_void()+ylim(-55,90)+
  theme(legend.position = "bottom")
map_list2[[index]] <- g
  }}

ggarrange(plotlist = map_list, nrow = 3, ncol = 2, common.legend = T, legend = "bottom")

ggarrange(plotlist = map_list2, nrow = 3, ncol = 2, common.legend = T, legend = "bottom")

4.3 Multimodel maps of cat mean


cmip6s$cat.AI <- factor(cmip6s$cat.AI, levels = c("Hyperarid","Arid","Semi-arid","Dry subhumid","Humid","Cold"))

map_list <- list()

for(i in c("1850_1880", "1970_2000","1985_2015")){
g <- ggplot() + 
  geom_tile(data = subset(cmip6s, period == i & model == "historical"), aes(x=lon, y = lat,  fill = cat.AI))+
  geom_point(data = subset(cmip6s,nb.maj > 10), aes(x = lon, y = lat), shape = "'", col = "grey60")+
  borders(colour = "grey60")+
  scale_fill_manual(values =  col.cat, na.translate = F)+
  labs(title = paste("Category AI",i , sep = " "), fill = "")+
  theme_void()+ylim(-55,90)+
  theme(legend.position = "bottom")
map_list[[i]] <- g
}

ggarrange(plotlist = map_list, ncol = 1, nrow = 3, common.legend = T, legend = "bottom")


map_list <- list()

for(i in c("SSP245","SSP370","SSP585")){
  for (j in c("2030_2060","2070_2100")){
index <- paste(i, j, sep = " , ")
g <- ggplot() + 
  geom_tile(data = subset(cmip6s, period == j & model == i), aes(x=lon, y = lat,  fill = cat.AI))+
  geom_point(data = subset(cmip6s,nb.maj > 10), aes(x = lon, y = lat), shape = ".", col = "grey20", size = 0.1)+
  borders(colour = "grey60")+
  scale_fill_manual(values =  col.cat, na.translate = F)+
  labs(title = paste("Category AI",index, sep = " "), fill = "")+
  theme_void()+ylim(-55,90)+
  theme(legend.position = "bottom")
map_list[[index]] <- g
  }}

ggpubr::ggarrange(plotlist = map_list,ncol = 2, nrow = 3, common.legend = T, legend = "bottom")

5 Maps multimodel AI

quantile(cmip6s$AI.mean, probs = seq(0,1,0.1), na.rm = T) 
##           0%          10%          20%          30%          40%          50% 
## 2.902197e-03 1.993698e-01 5.922059e-01 1.019621e+00 1.457766e+00 2.127218e+00 
##          60%          70%          80%          90%         100% 
## 3.578980e+00 1.168470e+01 2.438867e+01 4.856852e+01 5.329875e+06

ai.breaks <- c(0,0.03,0.2,0.5,0.65,1,10,20,30)
colscale <- colorvec[-c(5,6)]
map_list <- list()

for(i in c("1850_1880", "1970_2000","1985_2015")){
g <- ggplot() + geom_raster(data = subset(cmip6s, period == i & model == "historical"), aes(x=lon, y = lat,  fill = AI.mean))+
   borders(colour = "grey60")+
  binned_scale(aesthetics = "fill", breaks = ai.breaks, palette = function(x) colscale,
               guide = guide_legend(label.theme = element_text(angle = 0)))+
  labs(title = i, fill = "Aridity index")+
  theme_void()+ylim(-55,90)+
  theme(legend.position = "right")
map_list[[i]] <- g
}

ggpubr::ggarrange(plotlist = map_list, ncol = 1, nrow = 3, common.legend = T, legend = "bottom")


map_list <- list()

for(i in c("SSP245","SSP370","SSP585")){
  for (j in c("2030_2060","2070_2100")){
index <- paste(i, j, sep = " , ")
g <- ggplot() + geom_raster(data = subset(cmip6s, period == j & model == i), aes(x=lon, y = lat,  fill = AI.mean))+
   borders(colour = "grey60")+
  binned_scale(aesthetics = "fill", breaks = ai.breaks, palette = function(x) colscale,
               guide = guide_legend(label.theme = element_text(angle = 0)))+
  labs(fill = "Aridity index", title = index)+
  theme_void()+ylim(-55,90)+
  theme(legend.position = "bottom")
map_list[[index]] <- g
  }}

ggpubr::ggarrange(plotlist = map_list,ncol = 2, nrow = 3, common.legend = T, legend = "bottom")

6 AI changes over time and scenarios

v<-NULL
v2<-NULL
for (N in 5:30) {
  v<-c(v,sum(sapply(floor(2*N/3):N,function(i) choose(N,i)*(1/2)^N*2)))# proba d'avoir 2/3 de même signe à partir de N modèles, lorsque N change
  v2<-c(v2,sum(sapply(floor(2*N/3):N,function(i) choose(N,i)*(1/2)^N)))# proba d'avoir 2/3 de signe >0 à partir de N modèles, lorsque N change
}


plot(5:30,v,type="l",ylab="Proba(>2/3 models...)",xlab="Nb of models")
lines(5:30,v2,col="red")

6.1 Boxplot of changes AI

ggpubr::ggarrange(plotlist = list(
ggplot(subset(cmip6s, anomalies < 1 & anomalies > -1 & model == "historical"))+
  geom_boxplot(aes(x=period, y = - anomalies, col = period), outlier.size = 1)+
  scale_color_manual(values = c("#1A9850","#66BD63","#A6D96A"))+
  labs(x = "", y = "difference of AI between each period and\nthe reference period 1970-2000")+
  facet_grid(cols = vars(model))+
  theme_minimal() + theme(legend.position = "none"),
ggplot(subset(cmip6s, anomalies < 1 & anomalies > -1 & model != "historical"))+
  geom_boxplot(aes(x=period, y = anomalies, col = period), outlier.size = 1)+
  scale_color_manual(values = c("#FDAE61","#F46D43"))+
  scale_y_continuous(position = "right")+
  labs(y = "", x = "")+
  facet_grid(cols = vars(model))+
  theme_minimal() + theme(legend.position = "none")),
widths = c(1.5,3),
ncol = 2, nrow = 1
)

6.2 Strictly wetter or dryer (reference period: 1970-2000)

map_list <- list()

for(i in c("1850_1880","1985_2015")){
g <- ggplot() + geom_raster(data = subset(cmip6s, period == i & model == "historical" & anomalies > 0), aes(x=lon, y = lat,  fill = "wetter"))+
  geom_raster(data = subset(cmip6s, period == i & model == "historical" & anomalies < 0), aes(x=lon, y = lat,  fill = "dryer"))+
  borders(colour = "grey60")+
  scale_fill_manual(values =  c("#F46D43", "#74ADD1"), na.translate = F)+
  labs(title = paste("AI changes between",i , "and 1970-2000", sep = " "), fill = "")+
  theme_void()+ylim(-55,90)+
  theme(legend.position = "bottom")
map_list[[i]] <- g
}

ggarrange(plotlist = map_list, ncol = 2)


map_list <- list()

for(i in c("SSP245","SSP370","SSP585")){
  for (j in c("2030_2060","2070_2100")){
index <- paste(i, j, sep = " , ")
g <- ggplot() + geom_raster(data = subset(cmip6s, period == j & model == i & anomalies > 0), aes(x=lon, y = lat,  fill = "wetter"))+
  geom_raster(data = subset(cmip6s, period == j & model == i & anomalies < 0), aes(x=lon, y = lat,  fill = "dryer"))+
  borders(colour = "grey60")+
  scale_fill_manual(values = c("#F46D43", "#74ADD1"), na.translate = F)+
  labs(fill = "Compared to 1970-2000", title = i)+
  theme_void()+ylim(-55,90)+
  theme(legend.position = "bottom")
map_list[[index]] <- g
  }}



ggpubr::ggarrange(plotlist = map_list,ncol = 2, nrow = 3, common.legend = T, legend = "bottom")

6.3 Wetter or dryer, binned (reference period: 1970-2000)

ano.quantiles <- cmip6s %>% group_by(model, period) %>% summarise(q10 = quantile(anomalies, probs = 0.1, na.rm =T), 
                                                        q25 = quantile(anomalies, probs = 0.25, na.rm =T), 
                                                        q50 = quantile(anomalies, probs = 0.5, na.rm =T), 
                                                        q75 = quantile(anomalies, probs = 0.75, na.rm =T), 
                                                        q90 = quantile(anomalies, probs = 0.9, na.rm =T)) 

ano.quantiles <- cmip6s %>% summarise(q10 = quantile(anomalies, probs = 0.1, na.rm =T), 
                                                        q25 = quantile(anomalies, probs = 0.25, na.rm =T), 
                                                        q50 = quantile(anomalies, probs = 0.5, na.rm =T), 
                                                        q75 = quantile(anomalies, probs = 0.75, na.rm =T), 
                                                        q90 = quantile(anomalies, probs = 0.9, na.rm =T)) 
qbreaks <- c(-5, -1,-0.1, -0.01, 0, 0.01, 0.1, 1,5)
colscale <- c("#08519c", "#3182bd", "#6baed6", "#9ecae1", "#c6dbef", "#fddbc7", "#f4a582", "#d6604d", "#b2182b", "#67001f")

“Anomalies” is the multimodel AI average minus the reference AI (period 1970-2000). More blue: AI mean is superior to AI ref, hence wetter than the ref. More red: the anomalie is negative, hence AI mean is inferior to AI ref, hence dryer.

AS OF NOW THE SAME QUANTILES ARE USED FOR ALL MAPS.

map_list <- list()

for(i in c("1850_1880","1985_2015")){
  #quant = subset(ano.quantiles, model == "historical" & period == i)
  #b = quant[1,c(3:7)] %>% as.numeric
  b = qbreaks
g <- ggplot() + geom_raster(data = subset(cmip6s, period == i & model == "historical"), aes(x=lon, y = lat,  fill = anomalies))+
   borders(colour = "grey60")+
  binned_scale(aesthetics = "fill", breaks = b, palette = function(x) rev(colscale),
               guide = guide_legend(label.theme = element_text(angle = 0)))+
  labs(title = i, fill = "")+
  theme_void()+ylim(-55,90)+
  theme(legend.position = "right")
map_list[[i]] <- g
}

ggpubr::ggarrange(plotlist = map_list, ncol = 2, common.legend = T, legend = "bottom")


map_list <- list()

for(i in c("SSP245","SSP370","SSP585")){
  for (j in c("2030_2060","2070_2100")){
index <- paste(i, j, sep = " , ")
  b = qbreaks
g <- ggplot() + geom_raster(data = subset(cmip6s, period == j & model == i), aes(x=lon, y = lat,  fill = anomalies))+
   borders(colour = "grey60")+
  binned_scale(aesthetics = "fill", breaks = b, palette = function(x) rev(colscale),
               guide = guide_legend(label.theme = element_text(angle = 0)))+
  labs(fill = "Compared to 1970-2000", title = index)+
  theme_void()+ylim(-55,90)+
  theme(legend.position = "bottom")
map_list[[index]] <- g
  }}



ggpubr::ggarrange(plotlist = map_list,ncol = 2, nrow = 3, common.legend = T, legend = "bottom")

6.4 Wetter or dryer, binned, % (reference period: 1970-2000)

cmip6s$anomalies.percent <- with(cmip6s, (AI.mean-AI.ref)/AI.ref*100)
  
 
pbreaks <- c(-40, -30,-20, -10, 0, 10, 20, 30, 40)
colscale <- c("#08519c", "#3182bd", "#6baed6", "#9ecae1", "#c6dbef", "#fddbc7", "#f4a582", "#d6604d", "#b2182b", "#67001f")

“Anomalies” is the multimodel AI average minus the reference AI (period 1970-2000). More blue: AI mean is superior to AI ref, hence wetter than the ref. More red: the anomalie is negative, hence AI mean is inferior to AI ref, hence dryer.

map_list <- list()

for(i in c("1850_1880","1985_2015")){
  #quant = subset(ano.quantiles, model == "historical" & period == i)
  #b = quant[1,c(3:7)] %>% as.numeric
  b = pbreaks
g <- ggplot() + geom_raster(data = subset(cmip6s, period == i & model == "historical"), aes(x=lon, y = lat,  fill = anomalies.percent))+
   borders(colour = "grey60")+
  binned_scale(aesthetics = "fill", breaks = b, palette = function(x) rev(colscale),
               guide = guide_legend(label.theme = element_text(angle = 0)))+
  labs(title = i, fill = "")+
  theme_void()+ylim(-55,90)+
  theme(legend.position = "right")
map_list[[i]] <- g
}

ggpubr::ggarrange(plotlist = map_list, ncol = 1, nrow = 2, common.legend = T, legend = "bottom") %>% annotate_figure(top = "% change of AI index compared to 1970-2000")


map_list <- list()

for(i in c("SSP245","SSP370","SSP585")){
  for (j in c("2030_2060","2070_2100")){
index <- paste(i, j, sep = " , ")
  b = pbreaks
g <- ggplot() + geom_tile(data = subset(cmip6s, period == j & model == i), aes(x=lon, y = lat,  fill = anomalies.percent))+
   borders(colour = "grey60")+
  binned_scale(aesthetics = "fill", breaks = b, palette = function(x) rev(colscale),
               guide = guide_legend(label.theme = element_text(angle = 0)))+
  labs(fill = "% change of AI index\ncompared to 1970-2000", title = index)+
  theme_void()+ylim(-55,90)+
  theme(legend.position = "bottom")
map_list[[index]] <- g
  }}


ggpubr::ggarrange(plotlist = map_list,ncol = 2, nrow = 3, common.legend = T, legend = "bottom")

7 Difference between future and reference category of AI, using cat maj

7.1 Strictly dryer or wetter category cat maj


cmip6s$change.catmaj <- with(cmip6s, ifelse(cat.maj == catmajref, 0, 1))

map_list <- list()

for(i in c("1850_1880","1985_2015")){
g <- ggplot() + geom_raster(data = subset(cmip6s, period == i & model == "historical" & change.catmaj == 1), aes(x=lon, y = lat,  fill = dryer.maj))+
  borders(colour = "grey60")+
  scale_fill_manual(values =  c("#F46D43", "#74ADD1"), na.translate = F)+
  labs(title = paste("AI changes between", i , "and 1970-2000", sep = " "), fill = "")+
  theme_void()+ylim(-55,90)+
  theme(legend.position = "bottom")
map_list[[i]] <- g
}

ggarrange(plotlist = map_list, ncol = 2, common.legend = T)


map_list <- list()

for(i in c("SSP245","SSP370","SSP585")){
  for (j in c("2030_2060","2070_2100")){
index <- paste(i, j, sep = " , ")
g <- ggplot() + geom_raster(data = subset(cmip6s, period == j & model == i), aes(x=lon, y = lat,  fill = dryer.maj))+
   geom_raster(data = subset(cmip6s, period == j & model == "historical" & change.catmaj == 1 & nb.maj > 10), aes(x= lon, y = lat, fill = "'"))+
  borders(colour = "grey60")+
  scale_fill_manual(values = c("#F46D43", "#74ADD1"), na.translate = F)+
  labs(fill = "Compared to 1970-2000", title = index)+
  theme_void()+ylim(-55,90)+
  theme(legend.position = "bottom")
map_list[[index]] <- g
  }}



ggpubr::ggarrange(plotlist = map_list,ncol = 2, nrow = 3, common.legend = T, legend = "bottom")

7.2 Detailed differences cat maj

7.2.1 Detailed changes and colors cat maj

cmip6s$change.catmaj <- with(cmip6s, ifelse(cat.maj == catmajref, 0, 1))

cmip6s$change.cat.maj <- with(cmip6s, ifelse(catmajref == "Arid" & cat.maj %in% c("Cold","Humid"),"Arid to cold or humid",
                                      ifelse(catmajref == "Arid" & cat.maj %in% c("Semi-Arid","Dry subhumid"), "Arid to semi-arid or dry subhumid",
                                      ifelse(catmajref == "Arid" & cat.maj == "Hyperarid", "Arid to hyperarid",
                                      ifelse(catmajref == "Semi-arid" & cat.maj == "Dry subhumid", "Semi-arid to dry subhumid",
                                      ifelse(catmajref == "Semi-arid" & cat.maj == "Arid", "Semi-arid to arid",
                                      ifelse(catmajref == "Semi-arid" & cat.maj == "Hyperarid", "Semi-arid to hyperarid",
                                      ifelse(catmajref == "Semi-arid" & cat.maj %in% c("Humid","Cold"), "Semi-arid to humid or cold",
                                      ifelse(catmajref == "Dry subhumid" & cat.maj %in% c("Semi-arid","Arid","Hyperarid"), "Dry subhumid to arid, semi-arid or hyperarid",
                                      ifelse(catmajref == "Dry subhumid" & cat.maj %in% c("Humid","Cold"), "Dry subhumid to humid or cold",
                                      ifelse(catmajref == "Humid" & cat.maj == "Cold","Humid to cold",
                                      ifelse(catmajref == "Humid" & cat.maj %in% c("Dry subhumid", "Semi-arid"), "Humid to dry-subhumid or semi-arid",
                                      ifelse(catmajref == "Humid" & cat.maj %in% c("Arid", "Hyperarid"), "Humid to arid or hyperarid",
                                      ifelse(catmajref == "Cold" & cat.maj == "Humid", "Cold to humid", 
                                      ifelse(catmajref == "Cold" & cat.maj %in% c("Dry subhumid","Semi-arid","Arid","Hyperarid"), "Cold to dryland",
                                      ifelse(catmajref == "Hyperarid" & cat.maj == "Arid", "Hyperarid to arid",
                                      ifelse(catmajref == "Hyperarid" & cat.maj %in% c("Semi-arid","Dry-subhumid"),"Hyperarid to semi arid or dry subhumid",
                                      ifelse(catmajref == "Hyperarid" & cat.maj %in% c("Humid", "Cold"), "Hyperarid to humid or cold", NA
                                      ))))))))))))))))))

cmip6s$change.cat.maj <- factor(cmip6s$change.cat.maj, 
                                   levels = c("Arid to hyperarid","Semi-arid to arid", "Dry subhumid to arid, semi-arid or hyperarid", "Humid to dry-subhumid or semi-arid", "Cold to humid","Hyperarid to arid", "Arid to semi-arid or dry subhumid", "Dry subhumid to humid or cold", "Semi-arid to dry subhumid", "Semi-arid to humid or cold"))
table(cmip6s$change.cat.maj)
## 
##                            Arid to hyperarid 
##                                          491 
##                            Semi-arid to arid 
##                                         1462 
## Dry subhumid to arid, semi-arid or hyperarid 
##                                          649 
##           Humid to dry-subhumid or semi-arid 
##                                         3088 
##                                Cold to humid 
##                                         3700 
##                            Hyperarid to arid 
##                                          301 
##            Arid to semi-arid or dry subhumid 
##                                            4 
##                Dry subhumid to humid or cold 
##                                          201 
##                    Semi-arid to dry subhumid 
##                                          236 
##                   Semi-arid to humid or cold 
##                                          381

colors_changes <- c("Hyperarid to arid" = "#E7D7B6", 
                    "Arid to semi-arid or dry subhumid" = colorvec[7],
                    "Dry subhumid to humid or cold" = colorvec[8],
                    "Semi-arid to dry subhumid" = colorvec[9],
                    "Semi-arid to humid or cold" = colorvec[10],
                    "Humid to cold" = colorvec[11],
                    "Cold to humid" = "#E7D7B6", 
                    "Humid to dry-subhumid or semi-arid" = colorvec[5],
                    "Dry subhumid to arid, semi-arid or hyperarid" = colorvec[4],
                    "Semi-arid to arid" = colorvec[3],
                    "Arid to hyperarid" = colorvec[1])

7.2.2 Changes towards dryer categories cat maj

7.2.2.1 Historical

map_list <- list()

for(i in c("1850_1880","1985_2015")){
g <- ggplot() + 
  geom_raster(data = subset(cmip6s, period == i & model == "historical" & change.catmaj == 1 & dryer.maj == "dryer"), 
              aes(x=lon, y = lat,  fill = change.cat.maj))+
  borders(colour = "grey60")+
  scale_fill_manual(values =  colors_changes, na.translate = F)+
  labs(title = i, fill = "Change of category\ncompared to\n1970-2000")+
  theme_void()+ylim(-55,90)+
  theme(legend.position = "bottom")+guides(fill = guide_legend(nrow = 2))
map_list[[i]] <- g
}


ggarrange(plotlist = map_list, ncol = 2, common.legend = T, legend = "bottom")

7.2.2.1.1 Future

map_list <- list()

for(i in c("SSP245","SSP370","SSP585")){
  for (j in c("2030_2060","2070_2100")){
index <- paste(i, j, sep = " , ")
g <- ggplot() + geom_tile(data = subset(cmip6s, period == j & model == i & change.catmaj == 1 & dryer.maj == "dryer"), 
                            aes(x=lon, y = lat,  fill = change.cat.maj))+
#   geom_raster(data = subset(cmip6s, period == i & model == "historical" & change.catmaj == 1 & nb.maj > 10), aes(x= lon, y = lat, fill = "'"))+
  borders(colour = "grey60")+
  scale_fill_manual(values = colors_changes, na.translate = F)+
#  scale_fill_viridis_d()+
  labs(fill = "Change of category\ncompared to\n1970-2000", title = index)+
  theme_void()+ylim(-55,90)+
  theme(legend.position = "bottom")+guides(fill = guide_legend(nrow = 2))
map_list[[index]] <- g
  }}

ggarrange(plotlist = map_list,ncol = 2, nrow = 3, common.legend = T, legend = "bottom")

7.2.3 Changes towards wetter categories cat maj

7.2.3.1 Historical

map_list <- list()

for(i in c("1850_1880","1985_2015")){
g <- ggplot() + geom_raster(data = subset(cmip6s, period == i & model == "historical" & change.catmaj == 1 & dryer.maj == "wetter"), 
                            aes(x=lon, y = lat,  fill = change.cat.maj))+
  borders(colour = "grey60", ylim = c(-40,40))+
  scale_fill_manual(values =  colors_changes, na.translate = F)+
  labs(title = i, fill = "Change of category\ncompared to\n1970-2000")+
  theme_void()+
  ylim(-50,50)+
  theme(legend.position = "bottom")+guides(fill = guide_legend(nrow = 2))
map_list[[i]] <- g
}

ggarrange(plotlist = map_list, ncol = 2, common.legend = T, legend = "bottom")

7.2.3.2 Future


map_list <- list()

for(i in c("SSP245","SSP370","SSP585")){
  for (j in c("2030_2060","2070_2100")){
index <- paste(i, j, sep = " , ")
g <- ggplot() + geom_tile(data = subset(cmip6s, period == j & model == i & change.catmaj == 1 & dryer.maj == "wetter"), 
                            aes(x=lon, y = lat,  fill = change.cat.maj))+
  borders(colour = "grey60", ylim = c(-40,40))+
  scale_fill_manual(values = colors_changes, na.translate = F)+
  labs(fill = "Change of category\ncompared to\n1970-2000", title = index)+
  theme_void()+ylim(-50,50)+
  theme(legend.position = "bottom")+guides(fill = guide_legend(nrow = 2))
map_list[[index]] <- g
  }}

ggpubr::ggarrange(plotlist = map_list, nrow = 3, ncol = 2, common.legend = T, legend = "bottom")

8 Difference between future and reference category of AI, using cat mean

8.1 Stricly dryer or wetter category cat mean


cmip6s$change.catmean <- with(cmip6s, ifelse(cat.maj == catmajref, 0, 1))

map_list <- list()

for(i in c("1850_1880","1985_2015")){
g <- ggplot() + geom_raster(data = subset(cmip6s, period == i & model == "historical" & change.catmean == 1), aes(x=lon, y = lat,  fill = dryer))+
  borders(colour = "grey60")+
  scale_fill_manual(values =  c("#F46D43", "#74ADD1"), na.translate = F)+
  labs(title = paste("AI changes between",i , "and 1970-2000", sep = " "), fill = "")+
  theme_void()+ylim(-55,90)+
  theme(legend.position = "bottom")
map_list[[i]] <- g
}

ggarrange(plotlist = map_list, ncol = 2, common.legend = T, legend = "bottom")


map_list <- list()

for(i in c("SSP245","SSP370","SSP585")){
  for (j in c("2030_2060","2070_2100")){
index <- paste(i, j, sep = " , ")
g <- ggplot() + geom_raster(data = subset(cmip6s, period == j & model == i  & change.catmean == 1), aes(x=lon, y = lat,  fill = dryer))+
  borders(colour = "grey60")+
  scale_fill_manual(values = c("#F46D43", "#74ADD1"), na.translate = F)+
  labs(fill = "Compared to 1970-2000", title = index)+
  theme_void()+ylim(-55,90)+
  theme(legend.position = "bottom")
map_list[[index]] <- g
  }}

ggpubr::ggarrange(plotlist = map_list,ncol = 2, nrow = 3, common.legend = T, legend = "bottom")

8.2 Detailed differences cat mean

8.2.1 Detailed changes and colors

cmip6s$change.catmean <- with(cmip6s, ifelse(cat.AI == catAIref, 0, 1))

cmip6s$change.cat.mean <- with(cmip6s, ifelse(catAIref == "Arid" & cat.AI %in% c("Cold","Humid"),"Arid to cold or humid",
                                      ifelse(catAIref == "Arid" & cat.AI %in% c("Semi-Arid","Dry subhumid"), "Arid to semi-arid or dry subhumid",
                                      ifelse(catAIref == "Arid" & cat.AI == "Hyperarid", "Arid to hyperarid",
                                      ifelse(catAIref == "Semi-arid" & cat.AI == "Dry subhumid", "Semi-arid to dry subhumid",
                                      ifelse(catAIref == "Semi-arid" & cat.AI == "Arid", "Semi-arid to arid",
                                      ifelse(catAIref == "Semi-arid" & cat.AI == "Hyperarid", "Semi-arid to hyperarid",
                                      ifelse(catAIref == "Semi-arid" & cat.AI %in% c("Humid","Cold"), "Semi-arid to humid or cold",
                                      ifelse(catAIref == "Dry subhumid" & cat.AI %in% c("Semi-arid","Arid","Hyperarid"), "Dry subhumid to arid, semi-arid or hyperarid",
                                      ifelse(catAIref == "Dry subhumid" & cat.AI %in% c("Humid","Cold"), "Dry subhumid to humid or cold",
                                      ifelse(catAIref == "Humid" & cat.AI == "Cold","Humid to cold",
                                      ifelse(catAIref == "Humid" & cat.AI %in% c("Dry subhumid","Semi-arid"), "Humid to dry-subhumid or semi-arid",
                                      ifelse(catAIref == "Humid" & cat.AI %in% c("Arid", "Hyperarid"), "Humid to arid or hyperarid",
                                      ifelse(catAIref == "Cold" & cat.AI == "Humid", "Cold to humid", 
                                      ifelse(catAIref == "Cold" & cat.AI %in% c("Dry subhumid","Semi-arid","Arid","Hyperarid"), "Cold to dryland",
                                      ifelse(catAIref == "Hyperarid" & cat.AI == "Arid", "Hyperarid to arid",
                                      ifelse(catAIref == "Hyperarid" & cat.AI %in% c("Semi-arid","Dry-subhumid"),"Hyperarid to semi arid or dry subhumid",
                                      ifelse(catAIref == "Hyperarid" & cat.AI %in% c("Humid", "Cold"), "Hyperarid to humid or cold", NA
                                      ))))))))))))))))))

table(cmip6s$change.cat.mean)
## 
##                            Arid to hyperarid 
##                                          638 
##                                Cold to humid 
##                                         4370 
## Dry subhumid to arid, semi-arid or hyperarid 
##                                         2214 
##                Dry subhumid to humid or cold 
##                                          297 
##                                Humid to cold 
##                                          148 
##           Humid to dry-subhumid or semi-arid 
##                                         2624 
##                            Hyperarid to arid 
##                                          248 
##                            Semi-arid to arid 
##                                         1196 
##                    Semi-arid to dry subhumid 
##                                          276 
##                   Semi-arid to humid or cold 
##                                            1

cmip6s$change.cat.mean <- factor(cmip6s$change.cat.mean, 
                                   levels = c("Arid to hyperarid","Semi-arid to arid", "Dry subhumid to arid, semi-arid or hyperarid", "Humid to dry-subhumid or semi-arid", "Cold to humid","Hyperarid to arid", "Arid to semi-arid or dry subhumid", "Dry subhumid to humid or cold", "Semi-arid to dry subhumid", "Semi-arid to humid or cold"))
table(cmip6s$change.cat.mean)
## 
##                            Arid to hyperarid 
##                                          638 
##                            Semi-arid to arid 
##                                         1196 
## Dry subhumid to arid, semi-arid or hyperarid 
##                                         2214 
##           Humid to dry-subhumid or semi-arid 
##                                         2624 
##                                Cold to humid 
##                                         4370 
##                            Hyperarid to arid 
##                                          248 
##            Arid to semi-arid or dry subhumid 
##                                            0 
##                Dry subhumid to humid or cold 
##                                          297 
##                    Semi-arid to dry subhumid 
##                                          276 
##                   Semi-arid to humid or cold 
##                                            1

colors_changes <- c("Hyperarid to arid" = "#E7D7B6", 
                    "Arid to semi-arid or dry subhumid" = colorvec[7],
                    "Dry subhumid to humid or cold" = colorvec[8],
                    "Semi-arid to dry subhumid" = colorvec[9],
                    "Semi-arid to humid or cold" = colorvec[10],
                    "Humid to cold" = colorvec[11],
                    "Cold to humid" = "#E7D7B6",
                    "Humid to dry-subhumid or semi-arid" = colorvec[5],
                    "Dry subhumid to arid, semi-arid or hyperarid" = colorvec[4],
                    "Semi-arid to arid" = colorvec[3],
                    "Arid to hyperarid" = colorvec[1])

8.2.2 Changes towards dryer categories cat mean

8.2.2.1 Historical

map_list <- list()

for(i in c("1850_1880","1985_2015")){
g <- ggplot() + 
  geom_raster(data = subset(cmip6s, period == i & model == "historical" & change.catmean == 1 & dryer == "dryer"), 
              aes(x=lon, y = lat,  fill = change.cat.mean))+
  borders(colour = "grey60")+
  scale_fill_manual(values =  colors_changes, na.translate = F)+
  labs(title = i, fill = "Change of category\ncompared to\n1970-2000")+
  theme_void()+ylim(-55,90)+
  theme(legend.position = "bottom")+guides(fill = guide_legend(nrow = 2))
map_list[[i]] <- g
}

ggarrange(plotlist = map_list, ncol = 2, common.legend = T, legend = "bottom")

8.2.2.2 Future


map_list <- list()

for(i in c("SSP245","SSP370","SSP585")){
  for (j in c("2030_2060","2070_2100")){
index <- paste(i, j, sep = " , ")
g <- ggplot() + geom_tile(data = subset(cmip6s, period == j & model == i & change.catmean == 1 & dryer == "dryer"), 
                            aes(x=lon, y = lat,  fill = change.cat.mean))+
  borders(colour = "grey60")+
  scale_fill_manual(values = colors_changes)+
  labs(fill = "Change of category\ncompared to\n1970-2000", title = index)+
  theme_void()+ylim(-55,90)+
  theme(legend.position = "bottom")+guides(fill = guide_legend(nrow = 2))
map_list[[index]] <- g
  }}

ggarrange(plotlist = map_list, ncol = 2, nrow = 3, common.legend = T, legend = "bottom")

8.2.3 Changes towards wetter categories cat mean

8.2.3.1 Historical

map_list <- list()

for(i in c("1850_1880","1985_2015")){
g <- ggplot() + geom_tile(data = subset(cmip6s, period == i & model == "historical" & change.catmaj == 1 & dryer == "wetter"), 
                            aes(x=lon, y = lat,  fill = change.cat.mean))+
  borders(colour = "grey60", ylim = c(-40,40))+
  scale_fill_manual(values =  colors_changes, na.translate = F)+
  labs(title = i, fill = "Change of category\ncompared to\n1970-2000")+
  theme_void()+ylim(-50,50)+
  theme(legend.position = "bottom")+guides(fill = guide_legend(nrow = 2))
map_list[[i]] <- g
}

ggarrange(plotlist = map_list, ncol = 2, common.legend = T, legend = "bottom")

8.2.3.2 Future


map_list <- list()

for(i in c("SSP245","SSP370","SSP585")){
  for (j in c("2030_2060","2070_2100")){
index <- paste(i, j, sep = " , ")
g <- ggplot() + geom_tile(data = subset(cmip6s, period == j & model == i & change.catmean == 1 & dryer == "wetter"), 
                            aes(x=lon, y = lat,  fill = change.cat.mean))+
  borders(colour = "grey60", ylim = c(-40,40))+
  scale_fill_manual(values = colors_changes, na.translate = F)+
  labs(fill = "Change of category\ncompared to\n1970-2000", title = index)+
  theme_void()+
  theme(legend.position = "bottom")+guides(fill = guide_legend(nrow = 2))
map_list[[index]] <- g
  }}

ggpubr::ggarrange(plotlist = map_list,ncol = 2, nrow = 3, common.legend = T, legend = "bottom")

9 Tables

9.1 Changes of aridity category using cat mean

tab <- cmip6s %>% group_by(model, period, Continent) %>% summarise(Cold = table(cat.AI)[1], Hyperarid = table(cat.AI)[2], Arid = table(cat.AI)[3], Semiarid = table(cat.AI)[4], Drysubhumid = table(cat.AI)[5], Humid = table(cat.AI)[6], total = n()) 
write.table(tab, "tab.catAI.txt")

tab.future <- cmip6s %>% subset(!Continent %in% c("SOUTHERN","PACIFIC","ATLANTIC","INDIAN","ARCTIC")) %>%
  group_by(period, model, cat.AI) %>%
  summarise(count = n()) %>%
  ungroup() %>% group_by(period, model) %>% mutate(percent = round(count/sum(count)*100, 1), count = NULL) %>%
  reshape2::dcast(period + model ~cat.AI) %>%
  mutate("Sum drylands" = rowSums(.[c("Hyperarid","Arid","Semi-arid","Dry subhumid")])) %>%
  select(c("model","period","Hyperarid","Arid","Semi-arid","Dry subhumid","Sum drylands","Humid","Cold","NA"))

kable(tab.future[order(tab.future$model, decreasing = F),]) %>% kable_styling(bootstrap_options = "bordered") %>%
    column_spec(c(7,10), italic = T, include_thead = T) %>% row_spec(2, bold = T) 
model period Hyperarid Arid Semi-arid Dry subhumid Sum drylands Humid Cold NA
1 historical 1850_1880 3.4 6.0 7.1 3.3 19.8 28.8 48.9 2.6
2 historical 1970_2000 3.3 6.0 7.0 3.3 19.6 27.8 49.9 2.6
3 historical 1985_2015 3.3 6.1 6.9 3.3 19.6 27.3 50.6 2.6
4 SSP245 2030_2060 3.5 6.3 7.8 3.3 20.9 28.8 47.7 2.6
7 SSP245 2070_2100 3.6 6.4 7.8 3.5 21.3 29.4 46.6 2.6
5 SSP370 2030_2060 3.2 6.7 7.6 3.0 20.5 28.8 48.1 2.6
8 SSP370 2070_2100 4.0 6.3 8.3 3.7 22.3 28.5 46.6 2.6
6 SSP585 2030_2060 3.6 6.2 7.9 3.5 21.2 29.3 47.0 2.6
9 SSP585 2070_2100 3.8 6.4 8.4 3.6 22.2 30.1 45.1 2.6

# ggplot(tab.future, aes(x = period))+
#   geom_point(aes(y = Hyperarid, col = "Hyperarid", shape = model))+
#   geom_line(aes(y=Hyperarid, col = "Hyperarid", group = model, lty = model))+
#   geom_point(aes(y = Arid, col = "Arid", shape = model))+
#   geom_line(aes(y=Arid, col = "Arid", group = model, lty = model))+
#   geom_point(aes(y = get('Semi-arid'), col = "Semi-arid", shape = model))+
#   geom_line(aes(y=get('Semi-arid'), col = "Semi-arid", group = model, lty = model))+
#   geom_point(aes(y = get('Dry subhumid'), col = "Dry subhumid", shape = model))+
#   geom_line(aes(y=get('Dry subhumid'), col = "Dry subhumid", group = model, lty = model))+
#   geom_point(aes(y = Humid, col = "Humid", shape = model))+
#   geom_line(aes(y= Humid, col = "Humid", group = model, lty = model))+
#   scale_color_manual(values = col.cat)+
#   theme_minimal()

cmip6$cat.AI <- factor(cmip6$cat.AI, levels = c("Hyperarid", "Arid", "Semi-arid", "Dry subhumid", "Humid", "Cold"))
tab.percent <- cmip6 %>% subset(!Continent %in% c("SOUTHERN","PACIFIC","POLAR","ATLANTIC","INDIAN","ARCTIC")) %>%
  group_by(period, model, cat.AI, source) %>%
  summarise(count = n()) %>%
  ungroup() %>% 
  group_by(period, model, cat.AI) %>% 
  summarise(mmmean = mean(count, na.rm = T), mmsd = sd(count, na.rm = T)) %>%
  mutate(percent = round(mmmean/sum(mmmean)*100, 1), sd.percent = round(mmsd/sum(mmmean)*100,1)) 
write.table(tab.percent, "tab.percent.txt")
tab.percent <- read.table("tab.percent.txt")

df245 <- rbind(subset(tab.percent, model == "historical" & period %in% c("1850_1880", "1970_2000")), subset(tab.percent, model == "SSP245")) %>%
  group_by(period, model) %>% 
  mutate(lab.y = (rev(cumsum(rev(percent)))) - percent*0.5) %>% 
  subset(cat.AI %in% c("Hyperarid", "Arid", "Semi-arid", "Dry subhumid", "Humid","Cold"))

df245$cat.AI <- factor(df245$cat.AI, levels = c("Hyperarid", "Arid", "Semi-arid", "Dry subhumid", "Humid", "Cold"))

b245 <- ggplot(data = df245, aes(x = period, y = percent))+
  geom_col(aes(group = cat.AI, col = cat.AI, fill = cat.AI))+
  geom_label(aes(y = lab.y, label = paste(percent, " ± ", sd.percent, sep = "")), size = 3)+
  scale_color_manual(values = col.cat, aesthetics = c("col", "fill"), na.translate = F)+
  labs(title = "SSP 2-4.5", y = "%", x = "", col = "", fill = "")+
  theme_minimal()

df370 <- rbind(subset(tab.percent, model == "historical" & period %in% c("1850_1880", "1970_2000")), subset(tab.percent, model == "SSP370")) %>%
    group_by(period, model) %>% 
  mutate(lab.y = (rev(cumsum(rev(percent)))) - percent*0.5) %>% 
  subset(cat.AI %in% c("Hyperarid", "Arid", "Semi-arid", "Dry subhumid", "Humid","Cold"))

df370$cat.AI <- factor(df370$cat.AI, levels = c("Hyperarid", "Arid", "Semi-arid", "Dry subhumid", "Humid", "Cold"))

b370 <- ggplot(data = df370, aes(x = period, y = percent))+
  geom_col(aes(group = cat.AI, col = cat.AI, fill = cat.AI))+
  geom_label(aes(y = lab.y, label = paste(percent, " ± ", sd.percent, sep = "")), size = 3)+
  scale_color_manual(values = col.cat, aesthetics = c("col", "fill"), na.translate = F)+
  labs(title = "SSP 3-7.0", y = "%", x = "", col = "", fill = "")+
  theme_minimal()


df585 <- rbind(subset(tab.percent, model == "historical" & period %in% c("1850_1880", "1970_2000")), subset(tab.percent, model == "SSP585")) %>%
    group_by(period, model) %>% 
  mutate(lab.y = (rev(cumsum(rev(percent)))) - percent*0.5) %>% 
  subset(cat.AI %in% c("Hyperarid", "Arid", "Semi-arid", "Dry subhumid", "Humid","Cold"))

df585$cat.AI <- factor(df585$cat.AI, levels = c("Hyperarid", "Arid", "Semi-arid", "Dry subhumid", "Humid", "Cold"))

b585 <- ggplot(data = df585, aes(x = period, y = percent))+
  geom_col(aes(group = cat.AI, col = cat.AI, fill = cat.AI))+
  geom_label(aes(y = lab.y, label = paste(percent, " ± ", sd.percent, sep = "")), size = 3)+
  scale_color_manual(values = col.cat, aesthetics = c("col", "fill"), na.translate = F)+
  labs(title = "SSP 5-8.5", y = "%", x = "", col = "", fill = "")+
  theme_minimal()


ggarrange(plotlist = list(b245, b370, b585), common.legend = T, legend = "bottom", ncol = 3)

9.2 Changes of aridity category using cat maj

tab.maj <- cmip6s %>% group_by(model, period, Continent) %>% summarise(Cold = table(cat.maj)[1], Hyperarid = table(cat.maj)[2], Arid = table(cat.maj)[3], Semiarid = table(cat.maj)[4], Drysubhumid = table(cat.maj)[5], Humid = table(cat.maj)[6], total = n()) 
write.table(tab.maj, "tab.catmaj.txt")

tab.future.maj <- cmip6s %>% subset(!Continent %in% c("SOUTHERN","PACIFIC","ATLANTIC","INDIAN","ARCTIC")) %>%
  group_by(period, model, cat.maj) %>%
  summarise(count = n()) %>%
  ungroup() %>% group_by(period, model) %>% mutate(percent = round(count/sum(count)*100, 1), count = NULL) %>%
  reshape2::dcast(period + model ~cat.maj) %>%
  mutate("Sum drylands" = rowSums(.[c("Hyperarid","Arid","Semi-arid","Dry subhumid")])) %>%
  select(c("model","period","Hyperarid","Arid","Semi-arid","Dry subhumid","Sum drylands","Humid","Cold","NA"))

kable(tab.future.maj[order(tab.future.maj$model, decreasing = F),]) %>% kable_styling(bootstrap_options = "bordered") %>%
    column_spec(c(7,10), italic = T, include_thead = T) %>% row_spec(2, bold = T) 
model period Hyperarid Arid Semi-arid Dry subhumid Sum drylands Humid Cold NA
1 historical 1850_1880 4.2 7.1 8.7 0.8 20.8 28.3 48.3 2.6
2 historical 1970_2000 4.1 7.1 8.6 0.7 20.5 28.1 48.9 2.6
3 historical 1985_2015 4.0 7.0 8.4 0.9 20.3 27.3 49.9 2.6
4 SSP245 2030_2060 4.0 7.8 9.3 0.8 21.9 28.4 47.2 2.6
7 SSP245 2070_2100 4.2 7.7 9.4 0.9 22.2 29.1 46.1 2.6
5 SSP370 2030_2060 4.1 7.2 9.4 0.8 21.5 28.6 47.3 2.6
8 SSP370 2070_2100 4.5 7.7 10.0 0.9 23.1 28.4 45.9 2.6
6 SSP585 2030_2060 4.2 7.5 9.6 1.0 22.3 28.8 46.3 2.6
9 SSP585 2070_2100 4.5 7.9 9.4 0.9 22.7 30.0 44.6 2.6
tab.flow.catmaj <- cmip6s %>% subset(!Continent %in% c("SOUTHERN","PACIFIC","POLAR","ATLANTIC","INDIAN","ARCTIC")) %>%
  group_by(period, model, cat.maj) %>%
  summarise(count = n()) %>%
  ungroup() %>% group_by(period, model) %>% mutate(percent = round(count/sum(count)*100, 1), count = NULL)

df245 <- rbind(subset(tab.flow.catmaj, model == "historical" & period %in% c("1850_1880", "1970_2000")), subset(tab.flow.catmaj, model == "SSP245")) %>%
  mutate(lab.y = (rev(cumsum(rev(percent)))) - percent*0.5) %>% 
  subset(cat.maj %in% c("Hyperarid", "Arid", "Semi-arid", "Dry subhumid", "Humid","Cold"))

b245 <- ggplot(data = df245, aes(x = period, y = percent))+
  geom_col(aes(group = cat.maj, col = cat.maj, fill = cat.maj))+
  geom_label(aes(y = lab.y, label = percent))+
  scale_color_manual(values = col.cat, aesthetics = c("col", "fill"), na.translate = F)+
  labs(title = "SSP 2-4.5", y = "%", x = "")+
  theme_minimal()

df370 <- rbind(subset(tab.flow.catmaj, model == "historical" & period %in% c("1850_1880", "1970_2000")), subset(tab.flow.catmaj, model == "SSP370")) %>% mutate(lab.y = (rev(cumsum(rev(percent)))) - percent*0.5) %>% 
  subset(cat.maj %in% c("Hyperarid", "Arid", "Semi-arid", "Dry subhumid", "Humid","Cold"))

b370 <- ggplot(data = df370, aes(x = period, y = percent))+
  geom_col(aes(group = cat.maj, col = cat.maj, fill = cat.maj))+
  geom_label(aes(y = lab.y, label = percent))+
  scale_color_manual(values = col.cat, aesthetics = c("col", "fill"), na.translate = F)+
  labs(title = "SSP 3-7.0", y = "%", x = "")+
  theme_minimal()


df585 <- rbind(subset(tab.flow.catmaj, model == "historical" & period %in% c("1850_1880", "1970_2000")), subset(tab.flow.catmaj, model == "SSP585")) %>% mutate(lab.y = (rev(cumsum(rev(percent)))) - percent*0.5) %>% 
  subset(cat.maj %in% c("Hyperarid", "Arid", "Semi-arid", "Dry subhumid", "Humid","Cold"))

b585 <- ggplot(data = df585, aes(x = period, y = percent))+
  geom_col(aes(group = cat.maj, col = cat.maj, fill = cat.maj))+
  geom_label(aes(y = lab.y, label = percent))+
  scale_color_manual(values = col.cat, aesthetics = c("col", "fill"), na.translate = F)+
  labs(title = "SSP 5-8.5", y = "%", x = "")+
  theme_minimal()


ggarrange(plotlist = list(b245, b370, b585), common.legend = T, legend = "bottom", ncol = 3)

9.3 Changes by continent, cat mean


cmip6$cat.AI <- factor(cmip6$cat.AI, levels = c("Hyperarid", "Arid", "Semi-arid", "Dry subhumid", "Humid", "Cold"))
tab.percent.cont <- cmip6 %>% subset(!Continent %in% c("SOUTHERN","PACIFIC","POLAR","ATLANTIC","INDIAN","ARCTIC")) %>%
  group_by(period, model, Continent, cat.AI, source) %>%
  summarise(count = n()) %>%
  ungroup() %>% 
  group_by(period, model, Continent, cat.AI) %>% 
  summarise(mmmean = mean(count, na.rm = T), mmsd = sd(count, na.rm = T)) %>%
  mutate(percent = round(mmmean/sum(mmmean)*100, 1), sd.percent = round(mmsd/sum(mmmean)*100,1)) 
write.table(tab.percent.cont, "tab.percent.continent.txt")
tab.percent.cont <- read.table("tab.percent.continent.txt")

tab_list_percent <- list()
tab_list_sd <- list()

for(i in unique(tab.percent.cont$Continent)){
  tab.i <- subset(tab.percent.cont, Continent == i)

  df.percent <- tab.i %>% reshape2::dcast(period + model ~ cat.AI, value.var = "percent")

  df.sd <- tab.i %>% reshape2::dcast(period + model ~ cat.AI, value.var = "sd.percent")
  # sd for a sum: square root of sum of squared sd

  drycats <- which(names(df.percent) %in% c("Hyperarid","Arid","Semi-arid","Dry subhumid"))

  df.percent <- df.percent %>% mutate("Sum drylands" = rowSums(.[drycats], na.rm = T))
  df.sd <- df.sd %>% mutate("Sum drylands" = round(sqrt(rowSums((.[drycats])^2, na.rm = T)),2))
  
  missing <- setdiff(c("model","period","Hyperarid","Arid","Semi-arid","Dry subhumid","Sum drylands","Humid","Cold","NA"), names(df.percent))

  df.percent[, missing] <- 0
  df.sd[,missing] <- 0
                       
  df.percent <- df.percent %>% select(c("model","period","Hyperarid","Arid","Semi-arid","Dry subhumid","Sum drylands","Humid","Cold","NA"))
  df.percent[is.na(df.percent)] <- 0
  
  tab_list_percent[[i]] <- df.percent
  
  df.sd <- df.sd %>% select(c("model","period","Hyperarid","Arid","Semi-arid","Dry subhumid","Sum drylands","Humid","Cold","NA"))
  df.sd[is.na(df.sd)] <- 0
  
  tab_list_sd[[i]] <- df.sd
}

k_list <- list()
kdiff_list <- list()

for(i in names(tab_list_percent)){
  
  df <- tab_list_percent[[i]] %>% select(c("model", "period"))
  
  prop.ref <- tab_list_percent[[i]] %>% filter(period == "1970_2000")
  prop.ref <- prop.ref %>% rbind(prop.ref[rep(1,8),])
  df2 <- tab_list_percent[[i]][,c(3:10)] - prop.ref[,c(3:10)] %>% round(1)
  diff.prop.percent <- cbind(df, df2)
  
  sd.ref <- tab_list_sd[[i]] %>% filter(period == "1970_2000")
  sd.ref <- sd.ref %>% rbind(sd.ref[rep(1,8),])
  df3 <- sqrt(tab_list_sd[[i]][,c(3:10)]^2 + sd.ref[,c(3:10)]^2) %>% round(1)
  diff.sd.percent <- cbind(df, df3)
  
  df$Hyperarid <- paste(tab_list_percent[[i]]$Hyperarid, tab_list_sd[[i]]$Hyperarid, sep = " ± ")
  df$Arid <- paste(tab_list_percent[[i]]$Arid, tab_list_sd[[i]]$Arid, sep = " ± ")
  df$'Semi-Arid' <- paste(tab_list_percent[[i]][,5], tab_list_sd[[i]][,5], sep = " ± ")
  df$'Dry subhumid' <- paste(tab_list_percent[[i]][,6], tab_list_sd[[i]][,6], sep = " ± ")
  df$'Sum drylands' <- paste(tab_list_percent[[i]][,7], tab_list_sd[[i]][,7], sep = " ± ")
  df$Humid <- paste(tab_list_percent[[i]]$Humid, tab_list_sd[[i]]$Humid, sep = " ± ")
  df$Cold <- paste(tab_list_percent[[i]]$Cold, tab_list_sd[[i]]$Cold, sep = " ± ")
  
  df.diff <- df
  df.diff$Hyperarid <- paste(round(diff.prop.percent$Hyperarid, 1), round(diff.sd.percent$Hyperarid, 1), sep = " ± ")
  df.diff$Arid <- paste(round(diff.prop.percent$Arid, 1), round(diff.sd.percent$Arid, 1), sep = " ± ")
  df.diff$'Semi-Arid' <- paste(round(diff.prop.percent[,5], 1), round(diff.sd.percent[,5], 1), sep = " ± ")
  df.diff$'Dry subhumid' <- paste(round(diff.prop.percent[,6], 1), round(diff.sd.percent[,6], 1), sep = " ± ")
  df.diff$'Sum drylands' <- paste(round(diff.prop.percent[,7],1), round(diff.sd.percent[,7], 1), sep = " ± ")
  df.diff$Humid <- paste(round(diff.prop.percent$Humid, 1), round(diff.sd.percent$Humid, 1), sep = " ± ")
  df.diff$Cold <- paste(round(diff.prop.percent$Cold, 1), round(diff.sd.percent$Cold, 1), sep = " ± ")
    
  k_list[[i]] <- kable(df[order(df$model, decreasing = F),], caption = i) %>% kable_styling(bootstrap_options = "bordered") %>%
    column_spec(8, italic = T, background = colorvec[5]) %>% row_spec(2, bold = T) 
  kdiff_list[[i]] <- kable(df.diff[order(df.diff$model, decreasing = F),], caption = i) %>% kable_styling(bootstrap_options = "bordered") %>% 
    column_spec(8, italic = T, background = colorvec[5]) %>% row_spec(2, bold = T) 
  
}

9.3.1 Proportion of aridity categories by continent

k_list
$AFRICA
AFRICA
model period Hyperarid Arid Semi-Arid Dry subhumid Sum drylands Humid Cold
1 historical 1850_1880 27.2 ± 4.7 17.1 ± 4.9 15.6 ± 3.6 6.3 ± 1.4 66.2 ± 7.81 33.7 ± 7.1 0 ± 0
2 historical 1970_2000 26.9 ± 4.7 16.7 ± 4.2 15.1 ± 3.4 6.2 ± 1.5 64.9 ± 7.32 32.8 ± 6.2 2.3 ± 0
3 historical 1985_2015 26.5 ± 4.8 17.1 ± 4.6 15.4 ± 3.3 6 ± 1.5 65 ± 7.57 32.7 ± 6.3 2.2 ± 0
4 SSP245 2030_2060 27 ± 4.8 18 ± 4.9 16.5 ± 3.5 6.4 ± 1.7 67.9 ± 7.89 32 ± 7.6 0 ± 0
7 SSP245 2070_2100 27.9 ± 4.7 17.4 ± 5 17.2 ± 3.4 6.2 ± 1.5 68.7 ± 7.8 31.3 ± 7.9 0 ± 0
5 SSP370 2030_2060 26 ± 5 16.6 ± 3.6 17.2 ± 1.8 6.8 ± 1 66.6 ± 6.5 32.3 ± 6.7 1.1 ± 0
8 SSP370 2070_2100 28 ± 3.5 17.6 ± 4.8 16.6 ± 3.1 6.2 ± 1.6 68.4 ± 6.89 30.4 ± 6.4 1.2 ± 0
6 SSP585 2030_2060 27.1 ± 4.6 17.6 ± 4.8 16.8 ± 3.5 6.3 ± 1.5 67.8 ± 7.66 32.1 ± 7.5 0 ± 0
9 SSP585 2070_2100 29.7 ± 10.5 17.3 ± 5.3 16.2 ± 4.2 6 ± 1.5 69.2 ± 12.58 30.9 ± 8.6 0 ± 0
$ASIA
ASIA
model period Hyperarid Arid Semi-Arid Dry subhumid Sum drylands Humid Cold
1 historical 1850_1880 3.9 ± 2.3 12.2 ± 1.9 9.2 ± 1.5 4 ± 1.4 29.3 ± 3.62 32.4 ± 7.7 38 ± 9.2
2 historical 1970_2000 3.8 ± 2.1 12 ± 1.8 8.9 ± 1.5 3.8 ± 1.1 28.5 ± 3.33 30.7 ± 8.5 40.5 ± 9.6
3 historical 1985_2015 3.7 ± 2.2 11.8 ± 1.6 8.6 ± 1.5 3.7 ± 1.1 27.8 ± 3.3 30.1 ± 7.6 41.8 ± 8.8
4 SSP245 2030_2060 3.5 ± 1.8 12.5 ± 1.6 9.4 ± 1.6 4.3 ± 1.7 29.7 ± 3.35 34.3 ± 8.1 35.8 ± 9.2
7 SSP245 2070_2100 3.7 ± 2 12.5 ± 1.7 9.5 ± 1.7 4.2 ± 1.7 29.9 ± 3.56 36.2 ± 8.6 33.7 ± 9.3
5 SSP370 2030_2060 3.4 ± 2.3 12.4 ± 1.5 8.9 ± 1.7 3.7 ± 1.3 28.4 ± 3.48 34 ± 7.2 37.3 ± 9.5
8 SSP370 2070_2100 4.6 ± 1.9 12.5 ± 1.5 9.6 ± 1.5 3.8 ± 1.2 30.5 ± 3.09 35.2 ± 9.2 34.1 ± 9.7
6 SSP585 2030_2060 3.8 ± 2 12.5 ± 1.6 9.5 ± 1.8 4.2 ± 1.6 30 ± 3.52 35.4 ± 8.4 34.4 ± 9.3
9 SSP585 2070_2100 4.8 ± 3.2 13.1 ± 3.2 10.4 ± 3.4 4.2 ± 1.5 32.5 ± 5.86 36.5 ± 11.7 30.7 ± 9.9
$CENTRAL-AMERICA
CENTRAL-AMERICA
model period Hyperarid Arid Semi-Arid Dry subhumid Sum drylands Humid Cold
1 historical 1850_1880 0 ± 0 8.4 ± 3.6 30.1 ± 5.1 16.1 ± 8.7 54.6 ± 10.71 45 ± 6.1 0 ± 0
2 historical 1970_2000 0 ± 0 8.4 ± 4.1 29.7 ± 7.6 14.7 ± 7.8 52.8 ± 11.64 44.9 ± 12 2 ± 0
3 historical 1985_2015 0 ± 0 9 ± 4.2 30.7 ± 7 14.8 ± 7.4 54.5 ± 11.02 43.8 ± 11.5 1.4 ± 0
4 SSP245 2030_2060 0 ± 0 11.9 ± 6.2 36.3 ± 8 13.9 ± 6.2 62.1 ± 11.87 37.6 ± 8.6 0 ± 0
7 SSP245 2070_2100 0 ± 0 12.3 ± 5.5 38.1 ± 8.5 14.4 ± 7.9 64.8 ± 12.84 34.8 ± 8.6 0 ± 0
5 SSP370 2030_2060 0 ± 0 12.6 ± 6.3 31.4 ± 7.1 15 ± 7.9 59 ± 12.35 40.7 ± 11.8 0 ± 0
8 SSP370 2070_2100 4 ± 5.2 16 ± 5.5 35.5 ± 9.5 13.2 ± 5.2 68.7 ± 13.21 30.9 ± 10.6 0 ± 0
6 SSP585 2030_2060 0 ± 0 13 ± 7 37.6 ± 9 14.1 ± 7.1 64.7 ± 13.43 35 ± 9.4 0 ± 0
9 SSP585 2070_2100 2 ± 2.4 16.6 ± 8 41.2 ± 7.7 13.3 ± 7.7 73.1 ± 13.72 26.6 ± 8.8 0 ± 0
$EUROPE
EUROPE
model period Hyperarid Arid Semi-Arid Dry subhumid Sum drylands Humid Cold
1 historical 1850_1880 0 ± 0 1.9 ± 1.2 9.6 ± 4.1 4.5 ± 2.8 16 ± 5.11 49 ± 15.3 34.8 ± 20.2
2 historical 1970_2000 0 ± 0 1.5 ± 1 8.9 ± 3.4 3.9 ± 2.1 14.3 ± 4.12 44.9 ± 16.1 40.6 ± 20.4
3 historical 1985_2015 0 ± 0 1.3 ± 1 8.4 ± 2.9 3.8 ± 2 13.5 ± 3.66 46 ± 16.1 40.3 ± 19.9
4 SSP245 2030_2060 0 ± 0 1.9 ± 0.9 10.3 ± 3.6 5.1 ± 1.9 17.3 ± 4.17 52.7 ± 15.4 29.8 ± 19.7
7 SSP245 2070_2100 0 ± 0 2.2 ± 1.1 10.1 ± 4.8 5.1 ± 2.3 17.4 ± 5.44 55.4 ± 14.4 27 ± 18.6
5 SSP370 2030_2060 0 ± 0 2.1 ± 1 9.7 ± 4.7 4.8 ± 2.5 16.6 ± 5.42 52.7 ± 15.7 30.4 ± 20
8 SSP370 2070_2100 0 ± 0 3.1 ± 1.1 11.4 ± 5.9 6.4 ± 3.8 20.9 ± 7.1 52.8 ± 14.3 26 ± 18.6
6 SSP585 2030_2060 0 ± 0 2.3 ± 1.1 10.5 ± 3.7 4.9 ± 2.4 17.7 ± 4.55 55.2 ± 15.8 26.9 ± 19.9
9 SSP585 2070_2100 0 ± 0 3 ± 1.7 11.1 ± 5.4 6.1 ± 2.9 20.2 ± 6.36 57.2 ± 12.8 22.5 ± 17.3
$EUROPE-AFRICA
EUROPE-AFRICA
model period Hyperarid Arid Semi-Arid Dry subhumid Sum drylands Humid Cold
1 historical 1850_1880 5.9 ± 4.9 23.6 ± 7 21.3 ± 8.8 8.8 ± 3.3 59.6 ± 12.7 24.9 ± 14.2 14.5 ± 0
2 historical 1970_2000 7 ± 5.5 26.5 ± 7.5 23.3 ± 10.3 9.9 ± 3.2 66.7 ± 14.24 27.5 ± 16.5 4.5 ± 7.5
3 historical 1985_2015 7.1 ± 5.9 26.3 ± 7.1 22.2 ± 7.7 10.3 ± 4.2 65.9 ± 12.73 27.8 ± 14.3 5.2 ± 7
4 SSP245 2030_2060 9.9 ± 6.6 28.9 ± 8.6 26.7 ± 8.9 9.4 ± 3.4 74.9 ± 14.43 23.1 ± 16.2 0.9 ± 0
7 SSP245 2070_2100 11.7 ± 5.7 28.6 ± 8.8 27.2 ± 8.1 9.5 ± 3.1 77 ± 13.61 21.9 ± 13.9 0 ± 0
5 SSP370 2030_2060 10.3 ± 6.3 28.2 ± 8.4 26 ± 8.7 9 ± 2.8 73.5 ± 13.92 24.8 ± 14 0.5 ± 0
8 SSP370 2070_2100 13.2 ± 6.2 27.3 ± 8.6 28.3 ± 9.7 8.7 ± 3.6 77.5 ± 14.81 21.2 ± 16.2 0 ± 0
6 SSP585 2030_2060 11.1 ± 6.4 28.8 ± 8.3 27.5 ± 8.8 8.7 ± 3 76.1 ± 14.01 22.6 ± 14.1 0.2 ± 0
9 SSP585 2070_2100 15.2 ± 5.7 29.1 ± 10.1 27.9 ± 8.8 8 ± 2.8 80.2 ± 14.82 18.6 ± 13.6 0 ± 0
$NORTH-AMERICA
NORTH-AMERICA
model period Hyperarid Arid Semi-Arid Dry subhumid Sum drylands Humid Cold
1 historical 1850_1880 0 ± 0 0.4 ± 0.2 5.8 ± 5.6 4.3 ± 2.6 10.5 ± 6.18 35.1 ± 9 54.2 ± 10.9
2 historical 1970_2000 0 ± 0 0.4 ± 0.2 4.3 ± 4.4 4.2 ± 2.4 8.9 ± 5.02 34.5 ± 9.8 56.5 ± 11.7
3 historical 1985_2015 0 ± 0 0.3 ± 0.2 4.6 ± 3.8 4.1 ± 2.2 9 ± 4.4 33.6 ± 10.3 57.2 ± 11.5
4 SSP245 2030_2060 0 ± 0 0.4 ± 0.3 6.5 ± 5.5 4.7 ± 2.6 11.6 ± 6.09 37.5 ± 8.7 50.8 ± 11.1
7 SSP245 2070_2100 0 ± 0 0.5 ± 0.3 6.4 ± 5.1 5.1 ± 2.9 12 ± 5.87 39.7 ± 9 48.1 ± 11
5 SSP370 2030_2060 0 ± 0 0.5 ± 0.4 5.9 ± 4.8 4.6 ± 2.7 11 ± 5.52 37 ± 9.7 51.8 ± 12.2
8 SSP370 2070_2100 0.1 ± 0 0.8 ± 0.7 7.6 ± 4 5.2 ± 2 13.7 ± 4.53 38.4 ± 10.6 47.7 ± 11.2
6 SSP585 2030_2060 0 ± 0 0.5 ± 0.4 6.6 ± 5.2 5.2 ± 2.8 12.3 ± 5.92 38.2 ± 9.1 49.3 ± 11.7
9 SSP585 2070_2100 0.2 ± 0 1 ± 1.4 7 ± 6.1 5.2 ± 2.5 13.4 ± 6.74 42.1 ± 9.3 44.5 ± 11.3
$OCEANIA
OCEANIA
model period Hyperarid Arid Semi-Arid Dry subhumid Sum drylands Humid Cold
1 historical 1850_1880 5.3 ± 0 32 ± 26 36.7 ± 17.1 6.6 ± 3.1 80.6 ± 31.27 18.9 ± 12.5 0.3 ± 0.2
2 historical 1970_2000 5.2 ± 0 31.3 ± 26.4 36.8 ± 17.4 6.8 ± 3.1 80.1 ± 31.77 19.3 ± 12.8 0.5 ± 0.4
3 historical 1985_2015 5.2 ± 0 33.4 ± 26.1 35.5 ± 17.9 6.8 ± 3.2 80.9 ± 31.81 18.4 ± 12.3 0.6 ± 0.3
4 SSP245 2030_2060 10.4 ± 0 35.8 ± 23.5 31.7 ± 15.1 5.7 ± 2.6 83.6 ± 28.05 15.9 ± 11.9 0.3 ± 0.3
7 SSP245 2070_2100 10.5 ± 0 37.9 ± 22.2 29.1 ± 13.1 6.2 ± 3.3 83.7 ± 25.99 16.2 ± 12 0.1 ± 0
5 SSP370 2030_2060 10.7 ± 0 34.8 ± 22.6 33.4 ± 15.3 5.8 ± 2.5 84.7 ± 27.41 14.9 ± 8.1 0.3 ± 0.2
8 SSP370 2070_2100 10.5 ± 10.2 38.1 ± 19.7 28.5 ± 13.8 5.7 ± 3.2 82.8 ± 26.32 16.8 ± 16.3 0.3 ± 0.3
6 SSP585 2030_2060 5.6 ± 3.6 35.6 ± 25.3 33.8 ± 16.7 6.7 ± 3.6 81.7 ± 30.74 17.7 ± 13.8 0.3 ± 0.3
9 SSP585 2070_2100 9.3 ± 6.4 39.4 ± 21.7 29.4 ± 12.9 5.5 ± 2.5 83.6 ± 26.16 16.2 ± 12.5 0 ± 0
$SOUTH-AMERICA
SOUTH-AMERICA
model period Hyperarid Arid Semi-Arid Dry subhumid Sum drylands Humid Cold
1 historical 1850_1880 0.1 ± 0.1 2.1 ± 1.7 15.2 ± 8.7 7.4 ± 2.6 24.8 ± 9.24 73.2 ± 11.7 1.9 ± 1
2 historical 1970_2000 0.1 ± 0.1 1.8 ± 1.3 13.9 ± 4.3 7.3 ± 2.3 23.1 ± 5.05 74.5 ± 7.3 2.3 ± 2.6
3 historical 1985_2015 0.2 ± 0.1 2 ± 1.2 14.5 ± 5.1 7.5 ± 2.4 24.2 ± 5.76 73.6 ± 7.7 2.1 ± 2.6
4 SSP245 2030_2060 0.2 ± 0.2 2.7 ± 2.2 17.4 ± 9.6 8.8 ± 3.6 29.1 ± 10.49 69.4 ± 13.1 1.3 ± 0.9
7 SSP245 2070_2100 0.2 ± 0.1 3.3 ± 3.5 18.3 ± 9.1 9.3 ± 4.6 31.1 ± 10.78 67.5 ± 14.7 1.3 ± 0.7
5 SSP370 2030_2060 0.2 ± 0.1 2.2 ± 1.7 16.3 ± 5.5 8.8 ± 3.7 27.5 ± 6.84 70.5 ± 8.9 1.9 ± 1.6
8 SSP370 2070_2100 0.2 ± 0.1 3.3 ± 2.5 18.6 ± 7 8.7 ± 3.8 30.8 ± 8.35 67.3 ± 10.8 1.8 ± 1.8
6 SSP585 2030_2060 0.2 ± 0.1 3.1 ± 2.5 18.6 ± 9 9.2 ± 4.4 31.1 ± 10.33 67.6 ± 13.1 1.2 ± 0.8
9 SSP585 2070_2100 0.6 ± 1 4.4 ± 3.8 19.6 ± 9.5 9.7 ± 3.9 34.3 ± 11 64.4 ± 12.6 1.1 ± 0.7

9.3.2 Changes in proportion of aridity categories by continent

kdiff_list
$AFRICA
AFRICA
model period Hyperarid Arid Semi-Arid Dry subhumid Sum drylands Humid Cold
1 historical 1850_1880 0.3 ± 6.6 0.4 ± 6.5 0.5 ± 5 0.1 ± 2.1 1.3 ± 10.7 0.9 ± 9.4 -2.3 ± 0
2 historical 1970_2000 0 ± 6.6 0 ± 5.9 0 ± 4.8 0 ± 2.1 0 ± 10.4 0 ± 8.8 0 ± 0
3 historical 1985_2015 -0.4 ± 6.7 0.4 ± 6.2 0.3 ± 4.7 -0.2 ± 2.1 0.1 ± 10.5 -0.1 ± 8.8 -0.1 ± 0
4 SSP245 2030_2060 0.1 ± 6.7 1.3 ± 6.5 1.4 ± 4.9 0.2 ± 2.3 3 ± 10.8 -0.8 ± 9.8 -2.3 ± 0
7 SSP245 2070_2100 1 ± 6.6 0.7 ± 6.5 2.1 ± 4.8 0 ± 2.1 3.8 ± 10.7 -1.5 ± 10 -2.3 ± 0
5 SSP370 2030_2060 -0.9 ± 6.9 -0.1 ± 5.5 2.1 ± 3.8 0.6 ± 1.8 1.7 ± 9.8 -0.5 ± 9.1 -1.2 ± 0
8 SSP370 2070_2100 1.1 ± 5.9 0.9 ± 6.4 1.5 ± 4.6 0 ± 2.2 3.5 ± 10.1 -2.4 ± 8.9 -1.1 ± 0
6 SSP585 2030_2060 0.2 ± 6.6 0.9 ± 6.4 1.7 ± 4.9 0.1 ± 2.1 2.9 ± 10.6 -0.7 ± 9.7 -2.3 ± 0
9 SSP585 2070_2100 2.8 ± 11.5 0.6 ± 6.8 1.1 ± 5.4 -0.2 ± 2.1 4.3 ± 14.6 -1.9 ± 10.6 -2.3 ± 0
$ASIA
ASIA
model period Hyperarid Arid Semi-Arid Dry subhumid Sum drylands Humid Cold
1 historical 1850_1880 0.1 ± 3.1 0.2 ± 2.6 0.3 ± 2.1 0.2 ± 1.8 0.8 ± 4.9 1.7 ± 11.5 -2.5 ± 13.3
2 historical 1970_2000 0 ± 3 0 ± 2.5 0 ± 2.1 0 ± 1.6 0 ± 4.7 0 ± 12 0 ± 13.6
3 historical 1985_2015 -0.1 ± 3 -0.2 ± 2.4 -0.3 ± 2.1 -0.1 ± 1.6 -0.7 ± 4.7 -0.6 ± 11.4 1.3 ± 13
4 SSP245 2030_2060 -0.3 ± 2.8 0.5 ± 2.4 0.5 ± 2.2 0.5 ± 2 1.2 ± 4.7 3.6 ± 11.7 -4.7 ± 13.3
7 SSP245 2070_2100 -0.1 ± 2.9 0.5 ± 2.5 0.6 ± 2.3 0.4 ± 2 1.4 ± 4.9 5.5 ± 12.1 -6.8 ± 13.4
5 SSP370 2030_2060 -0.4 ± 3.1 0.4 ± 2.3 0 ± 2.3 -0.1 ± 1.7 -0.1 ± 4.8 3.3 ± 11.1 -3.2 ± 13.5
8 SSP370 2070_2100 0.8 ± 2.8 0.5 ± 2.3 0.7 ± 2.1 0 ± 1.6 2 ± 4.5 4.5 ± 12.5 -6.4 ± 13.6
6 SSP585 2030_2060 0 ± 2.9 0.5 ± 2.4 0.6 ± 2.3 0.4 ± 1.9 1.5 ± 4.8 4.7 ± 12 -6.1 ± 13.4
9 SSP585 2070_2100 1 ± 3.8 1.1 ± 3.7 1.5 ± 3.7 0.4 ± 1.9 4 ± 6.7 5.8 ± 14.5 -9.8 ± 13.8
$CENTRAL-AMERICA
CENTRAL-AMERICA
model period Hyperarid Arid Semi-Arid Dry subhumid Sum drylands Humid Cold
1 historical 1850_1880 0 ± 0 0 ± 5.5 0.4 ± 9.2 1.4 ± 11.7 1.8 ± 15.8 0.1 ± 13.5 -2 ± 0
2 historical 1970_2000 0 ± 0 0 ± 5.8 0 ± 10.7 0 ± 11 0 ± 16.5 0 ± 17 0 ± 0
3 historical 1985_2015 0 ± 0 0.6 ± 5.9 1 ± 10.3 0.1 ± 10.8 1.7 ± 16 -1.1 ± 16.6 -0.6 ± 0
4 SSP245 2030_2060 0 ± 0 3.5 ± 7.4 6.6 ± 11 -0.8 ± 10 9.3 ± 16.6 -7.3 ± 14.8 -2 ± 0
7 SSP245 2070_2100 0 ± 0 3.9 ± 6.9 8.4 ± 11.4 -0.3 ± 11.1 12 ± 17.3 -10.1 ± 14.8 -2 ± 0
5 SSP370 2030_2060 0 ± 0 4.2 ± 7.5 1.7 ± 10.4 0.3 ± 11.1 6.2 ± 17 -4.2 ± 16.8 -2 ± 0
8 SSP370 2070_2100 4 ± 5.2 7.6 ± 6.9 5.8 ± 12.2 -1.5 ± 9.4 15.9 ± 17.6 -14 ± 16 -2 ± 0
6 SSP585 2030_2060 0 ± 0 4.6 ± 8.1 7.9 ± 11.8 -0.6 ± 10.5 11.9 ± 17.8 -9.9 ± 15.2 -2 ± 0
9 SSP585 2070_2100 2 ± 2.4 8.2 ± 9 11.5 ± 10.8 -1.4 ± 11 20.3 ± 18 -18.3 ± 14.9 -2 ± 0
$EUROPE
EUROPE
model period Hyperarid Arid Semi-Arid Dry subhumid Sum drylands Humid Cold
1 historical 1850_1880 0 ± 0 0.4 ± 1.6 0.7 ± 5.3 0.6 ± 3.5 1.7 ± 6.6 4.1 ± 22.2 -5.8 ± 28.7
2 historical 1970_2000 0 ± 0 0 ± 1.4 0 ± 4.8 0 ± 3 0 ± 5.8 0 ± 22.8 0 ± 28.8
3 historical 1985_2015 0 ± 0 -0.2 ± 1.4 -0.5 ± 4.5 -0.1 ± 2.9 -0.8 ± 5.5 1.1 ± 22.8 -0.3 ± 28.5
4 SSP245 2030_2060 0 ± 0 0.4 ± 1.3 1.4 ± 5 1.2 ± 2.8 3 ± 5.9 7.8 ± 22.3 -10.8 ± 28.4
7 SSP245 2070_2100 0 ± 0 0.7 ± 1.5 1.2 ± 5.9 1.2 ± 3.1 3.1 ± 6.8 10.5 ± 21.6 -13.6 ± 27.6
5 SSP370 2030_2060 0 ± 0 0.6 ± 1.4 0.8 ± 5.8 0.9 ± 3.3 2.3 ± 6.8 7.8 ± 22.5 -10.2 ± 28.6
8 SSP370 2070_2100 0 ± 0 1.6 ± 1.5 2.5 ± 6.8 2.5 ± 4.3 6.6 ± 8.2 7.9 ± 21.5 -14.6 ± 27.6
6 SSP585 2030_2060 0 ± 0 0.8 ± 1.5 1.6 ± 5 1 ± 3.2 3.4 ± 6.1 10.3 ± 22.6 -13.7 ± 28.5
9 SSP585 2070_2100 0 ± 0 1.5 ± 2 2.2 ± 6.4 2.2 ± 3.6 5.9 ± 7.6 12.3 ± 20.6 -18.1 ± 26.7
$EUROPE-AFRICA
EUROPE-AFRICA
model period Hyperarid Arid Semi-Arid Dry subhumid Sum drylands Humid Cold
1 historical 1850_1880 -1.1 ± 7.4 -2.9 ± 10.3 -2 ± 13.5 -1.1 ± 4.6 -7.1 ± 19.1 -2.6 ± 21.8 10 ± 7.5
2 historical 1970_2000 0 ± 7.8 0 ± 10.6 0 ± 14.6 0 ± 4.5 0 ± 20.1 0 ± 23.3 0 ± 10.6
3 historical 1985_2015 0.1 ± 8.1 -0.2 ± 10.3 -1.1 ± 12.9 0.4 ± 5.3 -0.8 ± 19.1 0.3 ± 21.8 0.7 ± 10.3
4 SSP245 2030_2060 2.9 ± 8.6 2.4 ± 11.4 3.4 ± 13.6 -0.5 ± 4.7 8.2 ± 20.3 -4.4 ± 23.1 -3.6 ± 7.5
7 SSP245 2070_2100 4.7 ± 7.9 2.1 ± 11.6 3.9 ± 13.1 -0.4 ± 4.5 10.3 ± 19.7 -5.6 ± 21.6 -4.5 ± 7.5
5 SSP370 2030_2060 3.3 ± 8.4 1.7 ± 11.3 2.7 ± 13.5 -0.9 ± 4.3 6.8 ± 19.9 -2.7 ± 21.6 -4 ± 7.5
8 SSP370 2070_2100 6.2 ± 8.3 0.8 ± 11.4 5 ± 14.1 -1.2 ± 4.8 10.8 ± 20.5 -6.3 ± 23.1 -4.5 ± 7.5
6 SSP585 2030_2060 4.1 ± 8.4 2.3 ± 11.2 4.2 ± 13.5 -1.2 ± 4.4 9.4 ± 20 -4.9 ± 21.7 -4.3 ± 7.5
9 SSP585 2070_2100 8.2 ± 7.9 2.6 ± 12.6 4.6 ± 13.5 -1.9 ± 4.3 13.5 ± 20.6 -8.9 ± 21.4 -4.5 ± 7.5
$NORTH-AMERICA
NORTH-AMERICA
model period Hyperarid Arid Semi-Arid Dry subhumid Sum drylands Humid Cold
1 historical 1850_1880 0 ± 0 0 ± 0.3 1.5 ± 7.1 0.1 ± 3.5 1.6 ± 8 0.6 ± 13.3 -2.3 ± 16
2 historical 1970_2000 0 ± 0 0 ± 0.3 0 ± 6.2 0 ± 3.4 0 ± 7.1 0 ± 13.9 0 ± 16.5
3 historical 1985_2015 0 ± 0 -0.1 ± 0.3 0.3 ± 5.8 -0.1 ± 3.3 0.1 ± 6.7 -0.9 ± 14.2 0.7 ± 16.4
4 SSP245 2030_2060 0 ± 0 0 ± 0.4 2.2 ± 7 0.5 ± 3.5 2.7 ± 7.9 3 ± 13.1 -5.7 ± 16.1
7 SSP245 2070_2100 0 ± 0 0.1 ± 0.4 2.1 ± 6.7 0.9 ± 3.8 3.1 ± 7.7 5.2 ± 13.3 -8.4 ± 16.1
5 SSP370 2030_2060 0 ± 0 0.1 ± 0.4 1.6 ± 6.5 0.4 ± 3.6 2.1 ± 7.5 2.5 ± 13.8 -4.7 ± 16.9
8 SSP370 2070_2100 0.1 ± 0 0.4 ± 0.7 3.3 ± 5.9 1 ± 3.1 4.8 ± 6.8 3.9 ± 14.4 -8.8 ± 16.2
6 SSP585 2030_2060 0 ± 0 0.1 ± 0.4 2.3 ± 6.8 1 ± 3.7 3.4 ± 7.8 3.7 ± 13.4 -7.2 ± 16.5
9 SSP585 2070_2100 0.2 ± 0 0.6 ± 1.4 2.7 ± 7.5 1 ± 3.5 4.5 ± 8.4 7.6 ± 13.5 -12 ± 16.3
$OCEANIA
OCEANIA
model period Hyperarid Arid Semi-Arid Dry subhumid Sum drylands Humid Cold
1 historical 1850_1880 0.1 ± 0 0.7 ± 37.1 -0.1 ± 24.4 -0.2 ± 4.4 0.5 ± 44.6 -0.4 ± 17.9 -0.2 ± 0.4
2 historical 1970_2000 0 ± 0 0 ± 37.3 0 ± 24.6 0 ± 4.4 0 ± 44.9 0 ± 18.1 0 ± 0.6
3 historical 1985_2015 0 ± 0 2.1 ± 37.1 -1.3 ± 25 0 ± 4.5 0.8 ± 45 -0.9 ± 17.8 0.1 ± 0.5
4 SSP245 2030_2060 5.2 ± 0 4.5 ± 35.3 -5.1 ± 23 -1.1 ± 4 3.5 ± 42.4 -3.4 ± 17.5 -0.2 ± 0.5
7 SSP245 2070_2100 5.3 ± 0 6.6 ± 34.5 -7.7 ± 21.8 -0.6 ± 4.5 3.6 ± 41 -3.1 ± 17.5 -0.4 ± 0.4
5 SSP370 2030_2060 5.5 ± 0 3.5 ± 34.8 -3.4 ± 23.2 -1 ± 4 4.6 ± 42 -4.4 ± 15.1 -0.2 ± 0.4
8 SSP370 2070_2100 5.3 ± 10.2 6.8 ± 32.9 -8.3 ± 22.2 -1.1 ± 4.5 2.7 ± 41.3 -2.5 ± 20.7 -0.2 ± 0.5
6 SSP585 2030_2060 0.4 ± 3.6 4.3 ± 36.6 -3 ± 24.1 -0.1 ± 4.8 1.6 ± 44.2 -1.6 ± 18.8 -0.2 ± 0.5
9 SSP585 2070_2100 4.1 ± 6.4 8.1 ± 34.2 -7.4 ± 21.7 -1.3 ± 4 3.5 ± 41.2 -3.1 ± 17.9 -0.5 ± 0.4
$SOUTH-AMERICA
SOUTH-AMERICA
model period Hyperarid Arid Semi-Arid Dry subhumid Sum drylands Humid Cold
1 historical 1850_1880 0 ± 0.1 0.3 ± 2.1 1.3 ± 9.7 0.1 ± 3.5 1.7 ± 10.5 -1.3 ± 13.8 -0.4 ± 2.8
2 historical 1970_2000 0 ± 0.1 0 ± 1.8 0 ± 6.1 0 ± 3.3 0 ± 7.1 0 ± 10.3 0 ± 3.7
3 historical 1985_2015 0.1 ± 0.1 0.2 ± 1.8 0.6 ± 6.7 0.2 ± 3.3 1.1 ± 7.7 -0.9 ± 10.6 -0.2 ± 3.7
4 SSP245 2030_2060 0.1 ± 0.2 0.9 ± 2.6 3.5 ± 10.5 1.5 ± 4.3 6 ± 11.6 -5.1 ± 15 -1 ± 2.8
7 SSP245 2070_2100 0.1 ± 0.1 1.5 ± 3.7 4.4 ± 10.1 2 ± 5.1 8 ± 11.9 -7 ± 16.4 -1 ± 2.7
5 SSP370 2030_2060 0.1 ± 0.1 0.4 ± 2.1 2.4 ± 7 1.5 ± 4.4 4.4 ± 8.5 -4 ± 11.5 -0.4 ± 3.1
8 SSP370 2070_2100 0.1 ± 0.1 1.5 ± 2.8 4.7 ± 8.2 1.4 ± 4.4 7.7 ± 9.8 -7.2 ± 13 -0.5 ± 3.2
6 SSP585 2030_2060 0.1 ± 0.1 1.3 ± 2.8 4.7 ± 10 1.9 ± 5 8 ± 11.5 -6.9 ± 15 -1.1 ± 2.7
9 SSP585 2070_2100 0.5 ± 1 2.6 ± 4 5.7 ± 10.4 2.4 ± 4.5 11.2 ± 12.1 -10.1 ± 14.6 -1.2 ± 2.7

9.3.3 Changes in proportion of aridity categories, figure

list_plots <- list()

for(i in names(tab_list_percent)){
    df.percent <- tab_list_percent[[i]]
    df.sd <- tab_list_sd[[i]]
    
    df <- merge(df.percent, df.sd, by = c("model", "period"))
    
    g <- ggplot(data = df)+geom_point(aes(x=period,y= get("Sum drylands.x"), col = model), shape = "\u2605", size = 5, position = position_dodge(width = 0.5))+
      geom_errorbar(aes(x = period, ymin = get("Sum drylands.x")-get("Sum drylands.y"), ymax = get("Sum drylands.x")+get("Sum drylands.y"), col = model), position = position_dodge(width = 0.5))+
    scale_color_manual(values = colorvec[c(1,3,9,11)])+
      ylim(0,100)+
    labs(x="", y = "Percent of drylands", title = i)+
    theme_minimal()
  list_plots[[i]] <- g
}

ggarrange(plotlist = list_plots, ncol = 2, nrow = 4, common.legend = T, legend = "bottom")

tab.flow <- cmip6s %>% subset(!Continent %in% c("SOUTHERN","PACIFIC","POLAR","ATLANTIC","INDIAN","ARCTIC")) %>%
  group_by(period, model, Continent, cat.AI) %>%
  summarise(count = n()) %>%
  ungroup() %>% group_by(period, model, Continent) %>% mutate(percent = round(count/sum(count)*100, 1), count = NULL)

df245 <- rbind(subset(tab.flow, model == "historical" & period %in% c("1850_1880", "1970_2000")), subset(tab.flow, model == "SSP245")) %>% mutate(lab.y = (rev(cumsum(rev(percent)))) - percent*0.5) %>% 
  subset(cat.AI %in% c("Hyperarid", "Arid", "Semi-arid", "Dry subhumid", "Humid","Cold"))

b245 <- ggplot(data = df245, aes(x = period, y = percent))+
  geom_col(aes(group = cat.AI, col = cat.AI, fill = cat.AI))+
  geom_label(aes(y = lab.y, label = percent))+
  scale_color_manual(values = col.cat, aesthetics = c("col", "fill"), na.translate = F)+
  facet_grid(rows = vars(Continent), switch = "y")+
  scale_y_continuous(position = "right")+
  labs(title = "SSP 2-4.5", y = "%", x = "")+
  theme_minimal()

df370 <- rbind(subset(tab.flow, model == "historical" & period %in% c("1850_1880", "1970_2000")), subset(tab.flow, model == "SSP370")) %>% mutate(lab.y = (rev(cumsum(rev(percent)))) - percent*0.5) %>% 
  subset(cat.AI %in% c("Hyperarid", "Arid", "Semi-arid", "Dry subhumid", "Humid","Cold"))

b370 <- ggplot(data = df370, aes(x = period, y = percent))+
  geom_col(aes(group = cat.AI, col = cat.AI, fill = cat.AI))+
  geom_label(aes(y = lab.y, label = percent))+
  scale_color_manual(values = col.cat, aesthetics = c("col", "fill"), na.translate = F)+
  facet_grid(rows = vars(Continent), switch = "y")+
  scale_y_continuous(position = "right")+  labs(title = "SSP 3-7.0", y = "%", x = "")+
  theme_minimal()


df585 <- rbind(subset(tab.flow, model == "historical" & period %in% c("1850_1880", "1970_2000")), subset(tab.flow, model == "SSP585")) %>% mutate(lab.y = (rev(cumsum(rev(percent)))) - percent*0.5) %>% 
  subset(cat.AI %in% c("Hyperarid", "Arid", "Semi-arid", "Dry subhumid", "Humid","Cold"))

b585 <- ggplot(data = df585, aes(x = period, y = percent))+
  geom_col(aes(group = cat.AI, col = cat.AI, fill = cat.AI))+
  geom_label(aes(y = lab.y, label = percent))+
  scale_color_manual(values = col.cat, aesthetics = c("col", "fill"), na.translate = F)+
  facet_grid(rows = vars(Continent), switch = "y")+
  scale_y_continuous(position = "right")+  labs(title = "SSP 5-8.5", y = "%", x = "")+
  theme_minimal()


ggarrange(plotlist = list(b245, b370, b585), common.legend = T, legend = "bottom", ncol = 3)

10 Changes of variables over time and scenarios

10.1 Temperature

quantile(cmip6s$t.mean, probs = seq(0,1,0.1)) 
##          0%         10%         20%         30%         40%         50% 
## -53.4587313 -42.5828261 -28.4644864 -17.7502317  -7.2080554  -0.2580962 
##         60%         70%         80%         90%        100% 
##   7.1198406  15.3318920  22.8072968  26.4971129  34.3727997

t.breaks <- c(-50,-40,-30,-20,-10,0,10,20,30)
colscale <- c("#08519c", "#3182bd", "#6baed6", "#9ecae1", "#c6dbef", "#fddbc7", "#f4a582", "#d6604d", "#b2182b", "#67001f")
map_list <- list()

for(i in c("1850_1880", "1970_2000","1985_2015")){
g <- ggplot() + geom_raster(data = subset(cmip6s, period == i & model == "historical"), aes(x=lon, y = lat,  fill = t.mean))+
   borders(colour = "grey60")+
  binned_scale(aesthetics = "fill", breaks = t.breaks, palette = function(x) colscale,
               guide = guide_legend(label.theme = element_text(angle = 0)))+
  labs(title = i, fill = "Mean annual temperature, °C")+
  theme_void()+ylim(-55,90)+
  theme(legend.position = "right")
map_list[[i]] <- g
}

ggpubr::ggarrange(plotlist = map_list, ncol = 1, nrow = 3, common.legend = T, legend = "bottom")


map_list <- list()

for(i in c("SSP245","SSP370","SSP585")){
  for (j in c("2030_2060","2070_2100")){
index <- paste(i, j, sep = " , ")
g <- ggplot() + geom_raster(data = subset(cmip6s, period == j & model == i), aes(x=lon, y = lat,  fill = t.mean))+
   borders(colour = "grey60")+
  binned_scale(aesthetics = "fill", breaks = t.breaks, palette = function(x) colscale,
               guide = guide_legend(label.theme = element_text(angle = 0)))+
  labs(fill = "Mean annual temperature, °C", title = index)+
  theme_void()+ylim(-55,90)+
  theme(legend.position = "bottom")
map_list[[index]] <- g
  }}



ggpubr::ggarrange(plotlist = map_list,ncol = 2, nrow = 3, common.legend = T, legend = "bottom")


#labels = c("2030-2060", "2070-2100"

10.2 Precipitation

quantile(cmip6s$pr.mean, probs = seq(0,1,0.1)) 
##          0%         10%         20%         30%         40%         50% 
##    8.579696   55.000319  104.132310  200.852004  337.042710  463.946055 
##         60%         70%         80%         90%        100% 
##  579.741473  712.099280  959.490392 1431.315602 6863.723388

p.breaks <- c(10,50,100,200,300,400,500,600,700)
colscale <- c("#08519c", "#3182bd", "#6baed6", "#9ecae1", "#c6dbef", "#fddbc7", "#f4a582", "#d6604d", "#b2182b", "#67001f")
map_list <- list()

for(i in c("1850_1880","1970_2000","1985_2015")){
g <- ggplot() + geom_raster(data = subset(cmip6s, period == i & model == "historical"), aes(x=lon, y = lat,  fill = pr.mean))+
   borders(colour = "grey60")+
  binned_scale(aesthetics = "fill", breaks = p.breaks, palette = function(x) rev(colscale),
               guide = guide_legend(label.theme = element_text(angle = 0)))+
  labs(title = i, fill = "Annual mean precipitation")+
  theme_void()+ylim(-55,90)+
  theme(legend.position = "right")
map_list[[i]] <- g
}

ggpubr::ggarrange(plotlist = map_list, ncol = 1, nrow = 3, common.legend = T, legend = "bottom")


map_list <- list()

for(i in c("SSP245","SSP370","SSP585")){
  for (j in c("2030_2060","2070_2100")){
index <- paste(i, j, sep = " , ")
g <- ggplot() + geom_raster(data = subset(cmip6s, period == j & model == i), aes(x=lon, y = lat,  fill = pr.mean))+
   borders(colour = "grey60")+
  binned_scale(aesthetics = "fill", breaks = p.breaks, palette = function(x) rev(colscale),
               guide = guide_legend(label.theme = element_text(angle = 0)))+
  labs(fill = "Annual mean\nprecipitation, mm", title = index)+
  theme_void()+ylim(-55,90)+
  theme(legend.position = "bottom")
map_list[[index]] <- g
  }}

ggpubr::ggarrange(plotlist = map_list,ncol = 2, nrow = 3, common.legend = T, legend = "bottom")